Jump to content

GuiRegisterMsg(0x0100,'keydown')


Recommended Posts

Hi. I have a problem maybe someone knows why it does not work on the arrows do not;/

-keyup (0x0101) works

GUICreate("", 230, 300)
GUIRegisterMsg(0x0100, 'keydown')
GUISetState(@SW_SHOW)
Do
Until GUIGetMsg() = -3
Func keydown($q, $w, $e, $r)
    ConsoleWrite((Dec(Hex($e))))
EndFunc   ;==>keypress
Link to comment
Share on other sites

Did you check help files for function _WinAPI_SetWindowsHookEx()

some example (most code taken from help files):

#include <WindowsConstants.au3>
#include <WinAPI.au3>

$Form1 = GUICreate("", 230, 300)
GUISetState(@SW_SHOW)

OnAutoItExitRegister("_Cleanup")

$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

Do
Until GUIGetMsg() = -3

Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS, $keyCode
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If WinActive($Form1) then
        If $wParam = $WM_KEYDOWN then
            Local $keyCode = DllStructGetData($tKEYHOOKS, "vkCode")
            Switch $keyCode
                Case 37
                    ConsoleWrite('+ Arrow LEFT - pressed' & @CRLF)
                Case 38
                    ConsoleWrite('+ Arrow UP - pressed' & @CRLF)
                Case 39
                    ConsoleWrite('+ Arrow RIGHT - pressed' & @CRLF)
                Case 40
                    ConsoleWrite('+ Arrow DOWN - pressed' & @CRLF)
            EndSwitch
        ElseIf $wParam = $WM_KEYUP then
            Local $keyCode = DllStructGetData($tKEYHOOKS, "vkCode")
            Switch $keyCode
                Case 37
                    ConsoleWrite('! Arrow LEFT - released' & @CRLF)
                Case 38
                    ConsoleWrite('! Arrow UP - released' & @CRLF)
                Case 39
                    ConsoleWrite('! Arrow RIGHT - released' & @CRLF)
                Case 40
                    ConsoleWrite('! Arrow DOWN - released' & @CRLF)
            EndSwitch
        EndIf
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

Func _Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc
Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...