Ok, it is possible. For testing purposes, lets move our form when the focus is on some other window.
Module Code
Form CodeVB Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer Public 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 Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long Public Const HC_ACTION = 0 Public Const WM_KEYDOWN = &H100 Public Const WM_KEYUP = &H101 Public Const WM_SYSKEYDOWN = &H104 Public Const WM_SYSKEYUP = &H105 Public Const VK_CONTROL = &H11 Private Const VK_RSHIFT = &HA1 Public Const VK_MENU = &H12 Private Const VK_LEFT = &H25 Private Const VK_RIGHT = &H27 Public Const VK_UP = &H26 Public Const VK_DOWN = &H28 Public Const WH_KEYBOARD_LL = 13 Public Const LLKHF_ALTDOWN = &H20 Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Dim intFFN As Integer If (nCode = HC_ACTION) Then If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Then If (GetKeyState(VK_CONTROL) And &H8000) <> 0 Then If (GetKeyState(VK_MENU) And &H8000) <> 0 Then If (GetKeyState(VK_UP) And &H8000) <> 0 Then With Form1 .Move .Left, .Top - 100 End With ElseIf (GetKeyState(VK_DOWN) And &H8000) <> 0 Then With Form1 .Move .Left, .Top + 100 End With ElseIf (GetKeyState(VK_LEFT) And &H8000) <> 0 Then With Form1 .Move .Left - 100, .Top End With ElseIf (GetKeyState(VK_RIGHT) And &H8000) <> 0 Then With Form1 .Move .Left + 100, .Top End With End If End If End If End If End If KeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam) End Function
By pressing CTRL+ALT+UP, CTRL+ALT+DOWN, CTRL+ALT+LEFT, CTRL+ALT+RIGHT - the form will be moved accordingly even if you have the focus on some other window.VB Code:
Dim m_lngKeyboad As Long Private Sub Form_Unload(Cancel As Integer) If m_lngKeyboad <> 0 Then UnhookWindowsHookEx m_lngKeyboad End Sub Private Sub Form_Load() m_lngKeyboad = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeyboardProc, App.hInstance, 0) End Sub




Reply With Quote