Jump to content
Sign in to follow this  
lokuxd

GuiRegisterMsg(0x0100,'keydown')

Recommended Posts

lokuxd

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

Share this post


Link to post
Share on other sites
dragan

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
  • Like 2

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
lokuxd

but it works on other keyboards just not the arrows ;/

@2up thanks it works but why my code not work???

Edited by lokuxd

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.