Sowas?
Spoiler anzeigen
Skript:
#include "IsPressedCallBack.au3"
$hGUI = GUICreate("IsPressed-Control", 250, 250)
$idButton = GUICtrlCreateButton("Press a key!", 50, 50, 150, 150)
GUISetState()
_IsPressed_SetCheckInterval(10)
[/autoit] [autoit][/autoit] [autoit]For $i = 0x00 To 0xDD
_IsPressed_CallBackRegister(Hex($i, 2), "Print", 1)
Next
While True
$iMsg = GUIGetMsg()
Switch $iMsg
Case -3
Exit
EndSwitch
WEnd
Func Print($iKey)
GUICtrlSetData($idButton, "0x" & $iKey)
EndFunc
IsPressedCallBack.au3
Global $gaCallBacks[1][3]
Global $ghUser32 = DllOpen("user32.dll")
AdlibRegister("__IsPressed_CallBackHandler", 100)
OnAutoItExitRegister("__IsPressed_Shutdown")
; #FUNCTION# ====================================================================================================================
; Name ..........: _IsPressed_CallBackRegister
; Description ...:
; Syntax ........: _IsPressed_CallBackRegister($sHexKey, $sCallBack, $iMethod)
; Parameters ....: $sHexKey - A string value.
; $sCallBack - A string value.
; $iMethod - 0 = Normal _IsPressed; 1 = Just call on down; 2 = Just call on up
; Return values .: None
; Author ........: chesstiger (AutoIt.de)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _IsPressed_CallBackRegister($sHexKey, $sCallBack, $iMethod = 0)
$gaCallBacks[UBound($gaCallBacks) - 1][0] = $sHexKey
$gaCallBacks[UBound($gaCallBacks) - 1][1] = $sCallBack
$gaCallBacks[UBound($gaCallBacks) - 1][2] = $iMethod
ReDim $gaCallBacks[UBound($gaCallBacks) + 1][3]
EndFunc ;==>_IsPressed_CallBackRegister
Func _IsPressed_SetCheckInterval($iMS)
AdlibUnRegister("__IsPressed_CallBackHandler")
AdlibRegister("__IsPressed_CallBackHandler", $iMS)
EndFunc ;==>_IsPressed_SetCheckInterval
Func __IsPressed_CallBackHandler()
For $i = 0 To UBound($gaCallBacks) - 2 ;Last element is always empty
If __IsPressed($gaCallBacks[$i][0], $ghUser32) Then
Switch $gaCallBacks[$i][2]
Case 0 ;Normal _IsPressed
Call($gaCallBacks[$i][1], $gaCallBacks[$i][0])
Case 1 ;DOWN
Call($gaCallBacks[$i][1], $gaCallBacks[$i][0])
Do
Sleep(10)
Until Not __IsPressed($gaCallBacks[$i][0], $ghUser32)
Case 2 ;UP
Do
Sleep(10)
Until Not __IsPressed($gaCallBacks[$i][0], $ghUser32)
Call($gaCallBacks[$i][1], $gaCallBacks[$i][0])
EndSwitch
EndIf
Next
EndFunc ;==>__IsPressed_CallBackHandler
Func __IsPressed_Shutdown()
DllClose($ghUser32)
EndFunc ;==>__IsPressed_Shutdown
Func __IsPressed($sHexKey, $vDLL = 'user32.dll')
; From Misc.au3 by ezzetabi and Jon
Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
If @error Then Return SetError(@error, @extended, False)
Return BitAND($a_R[0], 0x8000) <> 0
EndFunc ;==>__IsPressed
chess