pieeater Posted May 19, 2011 Posted May 19, 2011 i'm trying to make a script that checks to see if the keys "the" are pressed right after each other, however i cant think of how i would do that. this is what i've tried and it didn't work #include <Misc.au3> Global $t[3] $t[0] = 0 $t[1] = 0 $t[2] = 0 While 1 If _IsPressed(54) Then TimerInit() $t[0] = 1 If TimerDiff(3000) Then $t[0] = 0 EndIf If _IsPressed(48) Then TimerInit() $t[1] = 1 If TimerDiff(3000) Then $t[1] = 0 EndIf If _IsPressed(45) Then TimerInit() $t[2] = 1 If TimerDiff(3000) Then $t[2] = 0 EndIf If $t[0] = 1 And $t[1] = 1 And $t[2] = 1 Then _func() WEnd Func _func() MsgBox(0,"title","text") EndFunc [spoiler]My UDFs: Login UDF[/spoiler]
ahmet Posted May 19, 2011 Posted May 19, 2011 (edited) Look in helpfile for parameter of TimerDiff().I think that it is better to use HotKeySet() $i=0 Global $init_1, $init_2, $init_3 HotKeySet("t","_T") HotKeySet("h","_H") HotKeySet("e","_E") While 1 Sleep(100) WEnd Func _func() $i=$i+1 ConsoleWrite($i& @CRLF) EndFunc Func _T() ConsoleWrite("T" & @CRLF) Global $init_1=TimerInit() ;~ ConsoleWrite("T" & @CRLF) EndFunc Func _H() If TimerDiff($init_1)<3000 Then Global $init_2=TimerInit() EndIf EndFunc Func _E() If TimerDiff($init_2)<3000 Then ConsoleWrite("true" & @CRLF) EndIf EndFunc Edit: added example Edited May 19, 2011 by ahmet
pieeater Posted May 19, 2011 Author Posted May 19, 2011 thanks that solved my problem, sorry i thought i was using TimerDiff() right thanks for the idea [spoiler]My UDFs: Login UDF[/spoiler]
wakillon Posted May 20, 2011 Posted May 20, 2011 (edited) Another way ... Global $KeyBoardLayoutArr = StringSplit ( "{LMouse}|{RMouse}|{}|(MMouse}|{}|{}|{}|{BACKSPACE}|{TAB}|{}|{}|{}|{ENTER}|{}|{}|{SHIFT}|{CTRL}|{ALT}|{PAUSE}|{CAPSLOCK}|{}|{}|{}|{}|{}|{}|{ESC}|" & _ "{}|{}|{}|{]|{SPACE}|{PGUP}|{PGDN}|{END}|{HOME}|{LEFT}|{UP}|{RIGHT}|{DOWN}|{SELECT}|{PRINTSCREEN}|{}|{PRINTSCREEN}|{INSERT}|{DEL}|{}|0|1|2|3|4|5|6|7|8|9|{}|{}|{}|{}|{}|{}|{}|a|b|c|d|e|f|g|h|i|" & _ "j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|{LWIN}|{RWIN}|{APPSKEY}|{}|{SLEEP}|{numpad0}|{numpad1}|{numpad2}|{numpad3}|{numpad4}|{numpad5}|{numpad6}|{numpad7}|{numpad8}|{numpad9}|{NUMPADMULT}|{NUMPADADD}|" & _ "{}|{NUMPADSUB}|{NUMPADDOT}|{NUMPADDIV}|{F1}|{F2}|{F3}|{F4}|{F5}|{F6}|{F7}|{F8}|{F9}|{F10}|{F11}|{F12}|{F13}|{F14}|{F15}|{F16}|{F17}|{F18}|{F19}|{F20}|{F21}|{F22}|{F23}|{F24}|{}|{}|{}|{}|{}|{}|{}|" & _ "{}|{NUMLOCK}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{SHIFT}|{SHIFT}|{CTRL}|{CTRL}|{ALT}|{ALT}|{BROWSER_BACK}|{BROWSER_FORWARD}|{BROWSER_REFRESH}|{BROWSER_STOP}|{BROWSER_SEARCH}|{BROWSER_FAVORITES}|" & _ "{BROWSER_HOME}|{VOLUME_MUTE}|{VOLUME_DOWN}|{VOLUME_UP}|{MEDIA_NEXT}|{MEDIA_PREV}|{MEDIA_STOP}|{MEDIA_PLAY_PAUSE}|{LAUNCH_MAIL}|{LAUNCH_MEDIA}|{LAUNCH_APP1}|{LAUNCH_APP2}|{}|{}|;|{+}|,|{-}|.|/|`|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|[|\|]|'", "|") Global $KeyIsPressedOld = '', $_String, $_StringToFind='the' While 1 $KeyIsPressed = _KeyIsPressed ( ) If $KeyIsPressed Then ;ConsoleWrite ( "-->-- $KeyIsPressed : " & $KeyIsPressed & @Crlf ) If $KeyIsPressed <> $KeyIsPressedOld Then ConsoleWrite ( "+->-- $KeyIsPressed : " & $KeyIsPressed & @Crlf ) $_String = $_String & $KeyIsPressed ConsoleWrite ( "!->-- $_String : " & $_String & @Crlf ) If StringInStr ( $_String, $_StringToFind ) Then MsgBox ( 262144, 'Match', 'The string "' & $_StringToFind & '" was found !', 5 ) $_String = '' EndIf $KeyIsPressedOld = $KeyIsPressed EndIf EndIf Sleep ( 10 ) WEnd Func _KeyIsPressed ( ) For $_I = 0 To 165 $a_R = DllCall ( "user32.dll", "int", "GetAsyncKeyState", "int", '0x' & Hex ( $_I, 2 ) ) If Not @error And BitAND ( $a_R[0], 0x8000 ) = 0x8000 Then Return $KeyBoardLayoutArr[$_I] Next EndFunc ;==> _KeyIsPressed ( ) Edited May 20, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
AdmiralAlkex Posted May 21, 2011 Posted May 21, 2011 Or look at the example for _WinAPI_SetWindowsHookEx() .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now