Cotino Posted July 4, 2018 Posted July 4, 2018 Hi, I'm trying to make it so while you hold A down, a script will run and A won't actually be pressed. Problem is : If i use _isPressed to check if A is pressed, it will spam A (because the key is held down) If i use HotKeySet to capture A, it works but it generates lag. I want to be able to detect a key hold without this key being pressed in windows. Is this even possible ? Example : (hold A or B ) #include <misc.au3> HotKeySet("{ESC}", "Quit") HotKeySet("b", "go") $flag = False $timer = TimerInit() $timeOld = 0 While 1 If _IsPressed("41") Then ; A key ConsoleWrite("_IsPressed | Timer : " & Int(TimerDiff($timer)) & " | Time since last check : " & Int(TimerDiff($timer) - $timeOld) & @CRLF) $timeOld = TimerDiff($timer) Sleep(450) EndIf Sleep(50) WEnd Func go() If NOT $flag then $flag = True ConsoleWrite("HotKeySet | Timer : " & Int(TimerDiff($timer)) & " | Time since last check : " & Int(TimerDiff($timer) - $timeOld) & @CRLF) $timeOld = TimerDiff($timer) Sleep(500) $flag = False EndIf EndFunc Func Quit() Exit EndFunc
Juvigy Posted July 4, 2018 Posted July 4, 2018 Why, what exactly do you want to accomplish? Am i understanding you correctly - you want to block the 'A' key?
Deye Posted July 4, 2018 Posted July 4, 2018 On 7/4/2018 at 9:58 AM, Cotino said: If i use _isPressed to check if A is pressed, it will spam A (because the key is held down) Expand Try BlockInput()
Cotino Posted July 4, 2018 Author Posted July 4, 2018 (edited) I tried BlockInput as well as BlockInputEx UDF, but it actually prevents the key from being pressed without capturing if you press it or not. I want to block the A key, but still be able to detect a key press/hold. I don't have a specific use, i just had several scripts where it could be useful - Overlay for instance, where you could only show the overlay while pressing a key, or spamming a key only while you press another key. Edited July 4, 2018 by Cotino
Developers Jos Posted July 4, 2018 Developers Posted July 4, 2018 On 7/4/2018 at 12:00 PM, Cotino said: I don't have a specific use, i just had several scripts where it could be useful - Overlay for instance, where you could only show the overlay while pressing a key, or spamming a key only while you press another key. Expand yea ... clear as mud SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Cotino Posted July 4, 2018 Author Posted July 4, 2018 (edited) Here's a practical application if you will : While i hold A, slow the mouse down without actually sending A, and speed the mouse back to normal on release. Slowing/Speeding the mouse can be done easily with DllCall("user32.dll", "int", "SystemParametersInfo", "int", 0x0071, "int", 0, "int", $speed, "int", 0) I would use this for a magnifier to get to a precise pixel. Edited July 4, 2018 by Cotino
Developers Jos Posted July 4, 2018 Developers Posted July 4, 2018 On 7/4/2018 at 1:32 PM, Cotino said: Here's a practical application if you will Expand Could be me but I have no idea what that could be useful for... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Cotino Posted July 4, 2018 Author Posted July 4, 2018 If you want to get the pixel color at a specific position with a magnifier but your mouse is too fast (happens to me a lot) Draw something with more precision on a game like pictionary online or just paint.
Deye Posted July 4, 2018 Posted July 4, 2018 (edited) typing "a" (no spam) #include <Misc.au3> #include <MsgBoxConstants.au3> #include <WinAPISys.au3> Local $hDLL = DllOpen("user32.dll") Local $hWnd = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()')) While 1 If _IsPressed("41", $hDLL) Then _WinAPI_RegisterHotKey($hWnd, 0x011B, 0, 0x41) ConsoleWrite("_IsPressed - a Key is pressed (no spam)." & @CRLF) ; Wait until key is released. While _IsPressed("41", $hDLL) Sleep(250) WEnd _WinAPI_UnregisterHotKey($hWnd, 0x011B) ConsoleWrite("_IsPressed - a Key was released." & @CRLF) ElseIf _IsPressed("1B", $hDLL) Then MsgBox($MB_SYSTEMMODAL, "_IsPressed", "The Esc Key was pressed, therefore we will close the application.") ExitLoop EndIf Sleep(250) WEnd DllClose($hDLL) Edited July 4, 2018 by Deye
Cotino Posted July 4, 2018 Author Posted July 4, 2018 That works perfectly fine ! I didn't know about _WinAPI_RegisterHotKey, but it does just what i needed. what's the reason behind 0x011B as ID ? From what i understand the ID can be anything we want ?
InnI Posted July 4, 2018 Posted July 4, 2018 Like a variant #include <Misc.au3> #include <WindowsConstants.au3> HotKeySet("a", "_func") HotKeySet("{esc}", "_exit") While Sleep(11) If _IsPressed("41") Then $t = TimerInit() GUICreate("", 200, 200, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetState() While _IsPressed("41") Sleep(11) WEnd GUIDelete() ConsoleWrite("Show time: " & Round(TimerDiff($t)) & @CRLF) EndIf WEnd Func _func() EndFunc Func _exit() Exit EndFunc
FrancescoDiMuro Posted July 4, 2018 Posted July 4, 2018 On 7/4/2018 at 1:45 PM, Cotino said: Draw something with more precision on a game like pictionary online or just paint. Expand Game Automation is not allowed here. Click here to see my signature: Reveal hidden contents ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Cotino Posted July 5, 2018 Author Posted July 5, 2018 Good thing it's not automation then. Also those are examples.
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