Belini Posted April 18, 2019 Posted April 18, 2019 Is there any way for function to be called only once when a hotkey is pressed without having to use _WinAPI_GetAsyncKeyState or _IsPressed to know when the key has been released? My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
Moderators Melba23 Posted April 18, 2019 Moderators Posted April 18, 2019 Belini, Unset the HotKey when entering the function: #include <MsgBoxConstants.au3> HotKeySet("^t", "_Func") HotKeySet("{ESC}", "_Exit") While 1 Sleep(100) WEnd Func _Func() HotKeySet("^t") MsgBox($MB_SYSTEMMODAL, "HotKey", "Only going to work once!") EndFunc Func _Exit() Exit EndFunc M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Belini Posted April 18, 2019 Author Posted April 18, 2019 Sorry @ Melba23 I was not clear, I want to call the function only when the hotkey is no longer pressed but I do not want to disable the hotkey, I will use this function for counting pulses and can not count more than once for as long as the key was pressed. My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
Nine Posted April 18, 2019 Posted April 18, 2019 #include <Misc.au3> HotKeySet("{F1}", "_Func") HotKeySet("{ESC}", "_Exit") While 1 Sleep(100) WEnd Func _Func() HotKeySet("{F1}") ConsoleWrite ("HotKey Only going to work once!" & @CRLF) While _IsPressed ("70") Sleep (10) WEnd ; do your stuff here HotKeySet("{F1}", "_Func") EndFunc Func _Exit() Exit EndFunc Maybe this ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Belini Posted April 18, 2019 Author Posted April 18, 2019 (edited) @Nine are very short pulses and with small interval between them so I can not use _IsPressed or _WinAPI_GetAsyncKeyState to know when the key was released, what I want is to use hotkeyset () but only count one pulse for as long as the key was pressed, I searched the hotkeyset () function documentation to see if I could make changes to it but could not find it. EDITED: when I use _IsPressed or _WinAPI_GetAsyncKeyState some pulses are not counted and when I use only hotkeyset I get all the pulses but when the key happens to get stuck it will count infinitely because hotkeyset calls the function all the time the key is pressed. Edited April 18, 2019 by Belini My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
BrewManNH Posted April 18, 2019 Posted April 18, 2019 Are your reaction times quicker than the delay in that loop? Seriously doubt it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Nine Posted April 18, 2019 Posted April 18, 2019 have you tested my code, cause I do think it does what you want...unless I don't understand “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Belini Posted April 18, 2019 Author Posted April 18, 2019 @BrewManNH as incredible as it seems I can not get all pulses using loop because they are very fast and the interval between them is also very small, I can only get all pulses using hotkeyset but if the key is stuck the count does not stop so I need to call the function only once until the button is released but only using hotkeyset. @Nine deactivating hotkey and using _Ispressed I had already tried and for this I mentioned in the first post I need to do without using _IsPressed or _WinAPI_GetAsyncKeyState My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
Nine Posted April 18, 2019 Posted April 18, 2019 The key pressed are not done by a human, right ? Those are generated by a machine. Anyway, if that doesn't work I would probably go with a callback approach... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Belini Posted April 18, 2019 Author Posted April 18, 2019 you're right, these wrists are generated by a note acceptor that sends out wrists when a ballot is placed. My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
Nine Posted April 18, 2019 Posted April 18, 2019 2 hours ago, Belini said: you're right, these wrists are generated by a note acceptor that sends out wrists when a ballot is placed. English is not my first language, but that seems to me like Egyptian. And I know nothing about it. Take a look at a global callback, I hardly can think of a faster method. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Bert Posted April 18, 2019 Posted April 18, 2019 I'm baffled at something - For what purpose you need this functionality? I've never heard the need for such a thing. The Vollatran project My blog: http://www.vollysinterestingshit.com/
jdelaney Posted April 18, 2019 Posted April 18, 2019 (edited) Define pulse, and wrists. Is a pulse a send? I'm not understanding if it's a programmatic send, or user based send. There is no way a human can send quicker than the 10 ms sleeps....that's 100 individual presses a second. You can remove all sleeps, but watch one of your cpu cores go up to 100% #include <Misc.au3> HotKeySet("{ESC}", "_Exit") $sendCount = 0 While 1 If _IsPressed("70") Then $sendCount += 1 While _IsPressed ("70") WEnd ContinueLoop EndIf Sleep(10) WEnd Func _Exit() MsgBox(1,1,$sendCount) Exit EndFunc if that's not fast enough, then AutoIT is not the solution you are looking for...slightly modified to include sleeps when the current loop did not have _ispressed. Proof of concept...I compiled and started the above, and then ran: AutoItSetOption("SendKeyDelay",5) For $i = 1 To 40 AutoItSetOption("SendKeyDownDelay",Random(10,100,1)) Send("{F1}") Next Send("{ESC}") The message box displayed 40 Just for fun, I did this one to see how fast I can send '0' repeatedly: HotKeySet("{ESC}", "_Exit") $j = TimerInit() $sendCount = 0 While 1 If _IsPressed("30") Then $i = TimerInit() $j = TimerDiff($j) While _IsPressed ("30") WEnd ConsoleWrite(TimerDiff($i) & @TAB & $j & @CRLF) $j = TimerInit() ContinueLoop EndIf Sleep(10) WEnd Func _Exit() Exit EndFunc output: TimeKeyIsDown|TimeWaitForNextSend expandcollapse popup38.5811 1433.9669 60.3951 75.5055 57.3372 63.8362 19.618 96.3084 35.7309 85.2414 10.7798 85.2756 38.7877 51.8923 42.2014 73.8966 41.3293 64.4828 29.7217 86.5125 37.8254 64.5799 55.5981 63.7196 52.7291 64.0097 52.5025 62.7217 38.963 77.1272 58.137 62.738 49.7552 76.4725 68.762 63.2584 55.5568 64.6286 36.5252 84.6798 75.4104 75.4531 53.4436 52.8638 44.8142 86.4005 61.8499 84.044 57.119 74.213 40.9023 95.4116 67.0561 84.0198 59.6137 61.6889 30.9173 95.3387 51.887 94.1365 42.998 63.1183 9.6173 116.8636 30.0914 85.7146 22.4921 93.7678 47.7521 84.4666 43.1216 61.6884 29.9012 86.1493 36.3007 84.6724 25.0176 86.1363 40.8244 84.9485 35.4981 85.6375 26.3855 84.7178 27.4497 73.2501 5.444 95.4684 humans are pretty slow...I was able to see 2 sends less than 10 MS , but that is an like in the 3 sigma range. I'd be lucky if I got 11 sends a second. Edited April 18, 2019 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Belini Posted April 19, 2019 Author Posted April 19, 2019 @jdelaney I'm traveling now and when I go back I'll do the tests, thanks for the tips. My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
Belini Posted April 23, 2019 Author Posted April 23, 2019 I got it using DllCall, thanks to everyone who gave tips. #include <WinAPI.au3> While 1 Key_IsPressed() GUIGetMsg() WEnd Func Key_IsPressed() local Static $count = 0, $state = 0 Local $Ret = DllCall('user32.dll', 'short', 'GetAsyncKeyState', 'int', 111); Checks if the NUMPADDIV key has been pressed If BitAND($Ret[0], 0x8000) > 0 And $state = 0 Then $count += 1 ConsoleWrite("Key pressed " & $count & @CRLF) $state = 1 Else If BitAND($Ret[0], 0x8000) = 0 And $state = 1 Then $state = 0 EndIf EndIf EndFunc ;==>Key_IsPressed My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
BrewManNH Posted April 23, 2019 Posted April 23, 2019 I thought you didn't want to use _IsPressed? Your code just does exactly what _IsPressed does. Func _IsPressed($sHexKey, $vDLL = "user32.dll") Local $aReturn = DllCall($vDLL, "short", "GetAsyncKeyState", "int", "0x" & $sHexKey) If @error Then Return SetError(@error, @extended, False) Return BitAND($aReturn[0], 0x8000) <> 0 EndFunc ;==>_IsPressed If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Belini Posted April 23, 2019 Author Posted April 23, 2019 GUIGetMsg() helped reduce key scanning time without overloading the processor. My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
BrewManNH Posted April 23, 2019 Posted April 23, 2019 39 minutes ago, Belini said: GUIGetMsg() helped reduce key scanning time Yeah, and a Sleep(10) would have done the same thing. You're just recreating or misusing functions because you're not paying attention to what you're doing and not reading the help file. So far in that script, you misused GUIGetMsg for no reason other than simply to insert a sleep into the script, where you could have used Sleep to do it. Then you recreated a function you said you wouldn't use, which doesn't make sense. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
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