EVENDO KEYDOWN NO MDIFORM

USUARIO.EXCLUIDOS 26/05/2007 11:34:20
#218351
Algém sabe algumo comando par acionar um evento similar ao keydown no MDIFORM


Tipo: Quando apertar a tecla F2 e abrir um form não child.

no form normal eu usava o seguinte codigo:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if keycode=vbkeyf2 then formdefora.show
End Sub


Mas no Mdiform o evento keydown não existe.
DANIELCPAETE 26/05/2007 12:02:01
#218356
você consegue verificar o evento keydown utilizando api's do windows ai vai um exemplo


'codigo do form mdi

Option Explicit

Private Sub MDIForm_Load()
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub

Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
UnhookWindowsHookEx hHook
End Sub



'codigo do modulo

Option Explicit

Public Const WH_KEYBOARD = 2
Public Const VK_F1 = &H70
Public Const VK_F2 = &H71
Public Const VK_F3 = &H72
Public Const VK_F4 = &H73
Public Const VK_F5 = &H74
Public Const VK_F6 = &H75
Public Const VK_F7 = &H76
Public Const VK_F8 = &H77
Public Const VK_F9 = &H78
Public Const VK_F10 = &H79
Public Const VK_F11 = &H7A
Public Const VK_F12 = &H7B

Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long

Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If idHook < 0 Then
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
If (GetKeyState(VK_F3) And &HF0000000) Then
Form1.Show
End If

KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function
Tópico encerrado , respostas não são mais permitidas