Autechre Posted April 30, 2006 Share Posted April 30, 2006 Hello. A quick question about HotKey support. Regarding the HotKeySet function, is it possible to have two different functions for the same hotkey, with one function executed when the key is pressed and the other function executed when the key is depressed? Sort of like HotKeySet("{a down}", "Enable") HotKeySet("{a up}", "Disable") If not, will there be possibility to maybe include such functionality in future released? Thanks in advance. Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted April 30, 2006 Moderators Share Posted April 30, 2006 Hello. A quick question about HotKey support. Regarding the HotKeySet function, is it possible to have two different functions for the same hotkey, with one function executed when the key is pressed and the other function executed when the key is depressed? Sort of like HotKeySet("{a down}", "Enable") HotKeySet("{a up}", "Disable") If not, will there be possibility to maybe include such functionality in future released? Thanks in advance.You could try something like this. #include <Misc.au3> While 1 If _IsPressed(20) Then While _IsPressed(20) ToolTip("You have the spacebar pressed.") Sleep(100) WEnd ToolTip("You released the spacebar.") Sleep(3000) ExitLoop EndIf Sleep(100) WEnd Link to comment Share on other sites More sharing options...
Autechre Posted April 30, 2006 Author Share Posted April 30, 2006 You could try something like this. #include <Misc.au3> While 1 If _IsPressed(20) Then While _IsPressed(20) ToolTip("You have the spacebar pressed.") Sleep(100) WEnd ToolTip("You released the spacebar.") Sleep(3000) ExitLoop EndIf Sleep(100) WEnd Hrm, this looks like it might work, but the _IsPressed function doesn't seem to be defined in Misc.au3 nor is it part of the api set. Where is this function define? Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted April 30, 2006 Share Posted April 30, 2006 (edited) u must have beta to use Misc.au3http://www.autoitscript.com/autoit3/files/beta/autoit/i dont think you need beta but it comes in beta or here it is;=============================================================================== ; ; Description: _IsPressed ; Parameter(s): $s_hexKey - key to check for ; $v_dll = Handle to dll or default to user32.dll ; ; User CallTip: _IsPressed($s_hexKey[, $v_dll = 'user32.dll']) Check if key has been pressed. (required: <Misc.au3>) ; Return Value(s): 1 if true ; 0 if false ; Author(s): ezzetabi and Jon ; ;=============================================================================== Func _IsPressed($s_hexKey, $v_dll = 'user32.dll') ; $hexKey must be the value of one of the keys. ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is. Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc ;==>_Is_Key_Pressed Edited April 30, 2006 by thatsgreat2345 Link to comment Share on other sites More sharing options...
herewasplato Posted April 30, 2006 Share Posted April 30, 2006 (edited) Welcome to the forum.The beta version of AutoIt has the _IsPressed User Defined Function (UDF) included in the file named misc.au3. You'll need the beta version to run the code that big_daddy posted above... or try this code:;http://www.autoitscript.com/forum/index.php?s=&showtopic=5760 Opt("OnExitFunc", "endscript") $dll = DllOpen("user32.dll") While 1 If _IsPressed("41") Then Do ToolTip("test") Sleep(99) Until Not _IsPressed("41") EndIf ToolTip("") Sleep(99) WEnd Func _IsPressed($hexKey) Local $aR $hexKey = '0x' & $hexKey $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey) If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc;==>_IsPressed Func endscript() DllClose($dll) EndFunc;==>endscriptEdit: too slow again........Edit2: See this link for more info on the _IsPressed UDF:http://www.autoitscript.com/forum/index.ph...&showtopic=5760 Edited April 30, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 30, 2006 Moderators Share Posted April 30, 2006 (edited) And if you defintely want to use Hotkeys and Functions then maybe:HotKeySet('a', 'A_Down') While 1 Sleep(100000) WEnd Func A_Down() $count = 0 HotKeySet('a') While _IsPressed('41') $count += 1 ToolTip($count, 0, 0) Sleep(10) WEnd A_Up() HotKeySet('a', 'A_Down') EndFunc Func A_Up() ToolTip('') EndFunc Func _IsPressed($s_hexKey, $v_dll = 'user32.dll') Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFuncEdit: Forgot to add the _IsPressed() UDF, but others did anyway. Edited April 30, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
herewasplato Posted April 30, 2006 Share Posted April 30, 2006 (edited) SmOke_N, Would still need beta $count += 1 :-) Edit - but cool code - just had to go there didn't ya @Autechre, Get beta :-) It is stable. Edited April 30, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 30, 2006 Moderators Share Posted April 30, 2006 SmOke_N,Would still need beta$count += 1:-) , yeah, but if your not using Beta, it's like riding a bike with training wheels. Can be done, but just can't do all the tricks that make it fun! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Autechre Posted April 30, 2006 Author Share Posted April 30, 2006 Thanks! I have it everything working great now. Link to comment Share on other sites More sharing options...
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