ich hab eien frage wie kann ich gucken wie lange eine taste gedrückt wurde?
wie kann ich gucken wie lange eine taste gedrückt wurde?
-
- [ offen ]
-
Sithlord95 -
7. April 2009 um 12:17 -
Geschlossen -
Erledigt
-
-
da brauchst du den befehl _Ispressed
[autoit]
das ganze dann zb in einer while schleife sieht dann ungefähr so aus:$counter = 0
[/autoit]
While _Ispressed("41") ;41 ist zB A (siehe Liste unten)
Sleep(1000)
$counter = $counter + 1
WEnd
MsgBox(0,"","Die Taste wurde "&$counter&"Sekunden gedrückt.")
hau rein team2way -
Mahlzeit,
Wenn ich auf den Thread verweisen darf: _Ispressed
meine Lösung ist diese hier (Credits an alle aus dem Thread):
Du brauchst die Keys.ini datei mit folgendem inhalt:Spoiler anzeigen
[keys]
01=Left mouse button
02=Right mouse button
04=Middle mouse button (three-button mouse)
05=Windows 2000/XP: X1 mouse button
06=Windows 2000/XP: X2 mouse button
08=BACKSPACE key
09=TAB key
0C=CLEAR key
0D=ENTER key
10=SHIFT key
11=CTRL key
12=ALT key
13=PAUSE key
14=CAPS LOCK key
1B=ESC key
20=SPACEBAR
21=PAGE UP key
22=PAGE DOWN key
23=END key
24=HOME key
25=LEFT ARROW key
26=UP ARROW key
27=RIGHT ARROW key
28=DOWN ARROW key
29=SELECT key
2A=PRINT key
2B=EXECUTE key
2C=PRINT SCREEN key
2D=INS key
2E=DEL key
30=0 key
31=1 key
32=2 key
33=3 key
34=4 key
35=5 key
36=6 key
37=7 key
38=8 key
39=9 key
41=A key
42=B key
43=C key
44=D key
45=E key
46=F key
47=G key
48=H key
49=I key
4A=J key
4B=K key
4C=L key
4D=M key
4E=N key
4F=O key
50=P key
51=Q key
52=R key
53=S key
54=T key
55=U key
56=V key
57=W key
58=X key
59=Y key
5A=Z key
5B=Left Windows key
5C=Right Windows key
60=Numeric keypad 0 key
61=Numeric keypad 1 key
62=Numeric keypad 2 key
63=Numeric keypad 3 key
64=Numeric keypad 4 key
65=Numeric keypad 5 key
66=Numeric keypad 6 key
67=Numeric keypad 7 key
68=Numeric keypad 8 key
69=Numeric keypad 9 key
6A=Multiply key
6B=Add key
6C=Separator key
6D=Subtract key
6E=Decimal key
6F=Divide key
70=F1 key
71=F2 key
72=F3 key
73=F4 key
74=F5 key
75=F6 key
76=F7 key
77=F8 key
78=F9 key
79=F10 key
7A=F11 key
7B=F12 key
7C=F13 key
7D=F14 key
7E=F15 key
7F=F16 key
80H=F17 key
81H=F18 key
82H=F19 key
83H=F20 key
84H=F21 key
85H=F22 key
86H=F23 key
87H=F24 key
90=NUM LOCK key
91=SCROLL LOCK key
A0=Left SHIFT key
A1=Right SHIFT key
A2=Left CONTROL key
A3=Right CONTROL key
A4=Left MENU key
A5=Right MENU key
BA=;
BB==
BC=,
BD=-
BE=.
BF=/
C0=`
DB=[
DC=\
DD=]
und das hier ist mein Code:Spoiler anzeigen
[autoit]#include <Array.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <misc.au3>
#include <Timers.au3>$dll = DllOpen("user32.dll")
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$keys = IniReadSection("keys.ini", "keys")Local $starttime
[/autoit]
While 1
For $x = 1 To $keys[0][0]
If _IsPressed($keys[$x][0], $dll) Then
$key = $keys[$x][1]
$starttime = _Timer_Init()
While _IsPressed($keys[$x][0], $dll)
Sleep(1)
WEnd
ToolTip($key & " was pressed" & @CRLF & Round(_Timer_Diff($starttime) / 1000, 2) & " seconds")
Beep(500, 100)
EndIf
Next
Sleep(1)
WEnd -
Ich würde es so machen, wobei ich die gezählten sektunden real eher am Ende der Schleife in eine TxT-Datei schreiben würde wenn ich sie weiter nutzen möchte.
Spoiler anzeigen
[autoit]
[/autoit]
#include <Misc.au3>
$dll = DllOpen("user32.dll")
$counter = 0
While 1
Sleep(999)
If _IsPressed("41", $dll) Then
$counter = $counter + 1
Else
ExitLoop
EndIf
WEnd
DllClose($dll)
MsgBox(0,"","Die Taste wurde "&$counter&" Sekunden gedrückt.") -
Hi
Bei _IsPressed wird für jede Taste ein DllCall ausgeführt...
Ressourcenschonender ist diese Lösung:
Spoiler anzeigen
[autoit]
[/autoit] [autoit][/autoit] [autoit]
Global $aKeyState = _WinAPI_GetKeyboardState()
Global $aKeyTimer[256][2]
For $i = 0 To 255
$aKeyTimer[$i][0] = $aKeyState[$i]
NextGlobal $hGui = GUICreate("TestKeyTimer", 400, 50)
[/autoit] [autoit][/autoit] [autoit]
Global $hLabel = GUICtrlCreateLabel("", 2, 2, 396, 46)
GUISetState()While GUIGetMsg() <> -3
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$aKeyState = _WinAPI_GetKeyboardState()
For $i = 0 To 255
If $aKeyState[$i] < 0 And $aKeyState[$i] <> $aKeyTimer[$i][0] Then
$aKeyTimer[$i][0] = $aKeyState[$i]
$aKeyTimer[$i][1] = TimerInit()
ElseIf $aKeyState[$i] <> $aKeyTimer[$i][0] Then
$aKeyTimer[$i][0] = $aKeyState[$i]
GUICtrlSetData($hLabel, "Taste Nr.: " & $i & " ( CHR: " & Chr($i) & " ) war " & Round(TimerDiff($aKeyTimer[$i][1]), 2) & " ms lang gedrückt")
EndIf
Next
WEnd; #FUNCTION# ====================================================================================================================
[/autoit]
; Name...........: _WinAPI_GetKeyboardState
; Description ...: Returns the status of the 256 virtual keys
; Syntax.........: _WinAPI_GetKeyboardState($iFlag=0)
; Parameters ....: $iFlag - Return Type
; 0Returns an array[256]
;1Returns a string
; Return values .: Success - Array[256] or String containing status of 256 virtual keys
; Failure - False
; Author ........: Eukalyptus
; Modified.......:
; Remarks .......: If the high-order bit is 1, the key is down; otherwise, it is up.
;If the key is a toggle key, for example CAPS LOCK, then the low-order bit is 1
;when the key is toggled and is 0 if the key is untoggled
; Related .......: _IsPressed
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _WinAPI_GetKeyboardState($iFlag = 0)
Local $aDllRet, $lpKeyState = DllStructCreate("byte[256]")
$aDllRet = DllCall("User32.dll", "int", "GetKeyboardState", "ptr", DllStructGetPtr($lpKeyState))
If @error Then Return SetError(@error, 0, 0)
If $aDllRet[0] = 0 Then
Return SetError(1, 0, 0)
Else
Switch $iFlag
Case 0
Local $aReturn[256]
For $i = 1 To 256
$aReturn[$i - 1] = DllStructGetData($lpKeyState, 1, $i)
Next
Return $aReturn
Case Else
Return DllStructGetData($lpKeyState, 1)
EndSwitch
EndIf
EndFunc ;==>_WinAPI_GetKeyboardStateAllerdings bekommt man damit nur Resultate, wenn man den Fokus im GUI hat!
(Man kann nicht prüfen, welche Taste z.b. im Notepad gedrückt wurde - und das ist auch gut so ;))lgE
-
- danke funzt das eigentlich auch wenn man 2 tasten gleichzeitig drückt?
[autoit]
naja ich hab noch ein prob
[/autoit]
#include <Misc.au3>
$dll = DllOpen("user32.dll")
$counter = 0
while 1
If _IsPressed("41") then
While 1
Sleep(1)
If _IsPressed("41", $dll) Then
$counter = $counter + 1
Else
ExitLoop
EndIf
WEnd
DllClose($dll)
$open = fileopen(@appdatadir&"\levelR.txt",1)
filewriteline($open,"a =" & $counter)
fileclose($open)
DllClose($dll)
endif
wendich will halt mit meinem kumpel gucken wer schneller tippen kann und
das das dann so ungefähr aufgelistet werden würde
zb so a = 30 also in tausendstel
aber bei mir wiederholt der das die ganze zeit was kann ich tun? -
Hi
Bei mir gehts nur bis zu 4 Tasten gleichzeitig
Spoiler anzeigen
[autoit]
[/autoit] [autoit][/autoit] [autoit]
Global $sLabel=""Global $aKeyState = _WinAPI_GetKeyboardState()
[/autoit] [autoit][/autoit] [autoit]
Global $aKeyTimer[256][2]
For $i = 0 To 255
$aKeyTimer[$i][0] = $aKeyState[$i]
NextGlobal $hGui = GUICreate("TestKeyTimer", 400, 400)
[/autoit] [autoit][/autoit] [autoit]
Global $hLabel = GUICtrlCreateLabel("", 2, 2, 396, 396)
GUISetState()While GUIGetMsg() <> -3
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$aKeyState = _WinAPI_GetKeyboardState()
For $i = 0 To 255
If $aKeyState[$i] < 0 And $aKeyState[$i] <> $aKeyTimer[$i][0] Then
$aKeyTimer[$i][0] = $aKeyState[$i]
$aKeyTimer[$i][1] = TimerInit()
ElseIf $aKeyState[$i] <> $aKeyTimer[$i][0] Then
$aKeyTimer[$i][0] = $aKeyState[$i]
$sLabel&= "Taste Nr.: " & $i & " ( CHR: " & Chr($i) & " ) war " & Round(TimerDiff($aKeyTimer[$i][1]), 2) & " ms lang gedrückt" & @LF
GUICtrlSetData($hLabel,$sLabel)
EndIf
Next
WEnd; #FUNCTION# ====================================================================================================================
[/autoit]
; Name...........: _WinAPI_GetKeyboardState
; Description ...: Returns the status of the 256 virtual keys
; Syntax.........: _WinAPI_GetKeyboardState($iFlag=0)
; Parameters ....: $iFlag - Return Type
; 0Returns an array[256]
;1Returns a string
; Return values .: Success - Array[256] or String containing status of 256 virtual keys
; Failure - False
; Author ........: Eukalyptus
; Modified.......:
; Remarks .......: If the high-order bit is 1, the key is down; otherwise, it is up.
;If the key is a toggle key, for example CAPS LOCK, then the low-order bit is 1
;when the key is toggled and is 0 if the key is untoggled
; Related .......: _IsPressed
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _WinAPI_GetKeyboardState($iFlag = 0)
Local $aDllRet, $lpKeyState = DllStructCreate("byte[256]")
$aDllRet = DllCall("User32.dll", "int", "GetKeyboardState", "ptr", DllStructGetPtr($lpKeyState))
If @error Then Return SetError(@error, 0, 0)
If $aDllRet[0] = 0 Then
Return SetError(1, 0, 0)
Else
Switch $iFlag
Case 0
Local $aReturn[256]
For $i = 1 To 256
$aReturn[$i - 1] = DllStructGetData($lpKeyState, 1, $i)
Next
Return $aReturn
Case Else
Return DllStructGetData($lpKeyState, 1)
EndSwitch
EndIf
EndFunc ;==>_WinAPI_GetKeyboardState -
bezieht sich das auch auf mein anderes problem oder nur auf das problem mit den gleichzeitigen tasten?
-
bezieht sich das auch auf mein anderes problem oder nur auf das problem mit den gleichzeitigen tasten?
Ja, also bei mir geht das auch mit drei Tasten. Vier? Dazu habe ich nicht die richtige Tastatur hier oder zu kleine Finger
-
und wie siehts aus mit meinem anderen problem das andere unter der frage mit den tasten