TheCrimsonCrusader Posted September 26 Share Posted September 26 Is there a way to do a <CTRL> + double tap of the "w" key as an example for hotkey assignment? Obviously with the below, it's going to process the <CTRL> and the first "w" immediately, so was curious if there is a way around that. Thanks. HotKeySet("^ww", "HotKeyPressed") Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted September 26 Share Posted September 26 Hi @TheCrimsonCrusader 👋 , as you already mentioned the function would be called at the first "w" which was hitten. So I strongly believe this is not achievable via HotKeySet. But with _IsPressed() you can do such combinations, with few conditions and so on. Why do you want this? Best regards Sven Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
argumentum Posted September 26 Share Posted September 26 1 hour ago, TheCrimsonCrusader said: Is there a way to do a <CTRL> + double tap of the "w" key as an example for hotkey assignment? HotKeySet("^ww", "HotKeyPressed") != HotKeySet("^w", "HotKeyPressed") + HotKeySet("^w", "HotKeyPressed") Run it in slow motion in your head and you'll see a delay between the first ^w and the next ^w So treat it as a double click, where you measure the time since the last ^w. If the second ^w is under 500 ms. then, is your trigger. You can code that idea Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
TheCrimsonCrusader Posted September 26 Author Share Posted September 26 39 minutes ago, SOLVE-SMART said: Hi @TheCrimsonCrusader 👋 , as you already mentioned the function would be called at the first "w" which was hitten. So I strongly believe this is not achievable via HotKeySet. But with _IsPressed() you can do such combinations, with few conditions and so on. Why do you want this? Best regards Sven I don't want to do this, my wife does for various e-mail signatures associated to a hotkey. 🙂 Apparently, Revit or one of her other architectural apps uses a hotkey sequence with a double-tap of the same letter and she likes it. Women. smh Link to comment Share on other sites More sharing options...
argumentum Posted September 26 Share Posted September 26 3 minutes ago, TheCrimsonCrusader said: uses a hotkey sequence with a double-tap of the same letter and she likes it. I'd like it too. Say you choose ^f. You can do it right now. You'll see that the browser thinks that you wanna find something. Do it twice for your trigger. Makes sense to like it. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Solution Popular Post TheXman Posted September 26 Solution Popular Post Share Posted September 26 (edited) 3 hours ago, TheCrimsonCrusader said: Is there a way to do a <CTRL> + double tap of the "w" key as an example for hotkey assignment? Here is a very simple example using the method described earlier by argumentum. Note the use of static variables. Doing it that way prevents the need to define those variables as Global. The example script sets up Ctrl+w and Ctrl+j as hotkeys to show how the method can be used for multiple hotkeys. The payload in each hotkey function will only execute if the hotkey is fired twice within the specified time, which in this case is 500 milliseconds (.5 seconds). Press ESC to exit the example. expandcollapse popup#include <Constants.au3> #include <Misc.au3> ;Declare constants Const $DOUBLE_CLICK_TIME = 500 ;Declare global vars Global $ghUserDll = DllOpen("user32.dll"), _ $ghCtrlWTimer = TimerInit(), _ $ghCtrlJTimer = TimerInit() ;Set hotkey(s) HotKeySet("^w", do_ctrl_w) HotKeySet("^j", do_ctrl_j) ;Loop until ESC pressed While 1 If _IsPressed("1B", $ghUserDll) then ExitLoop WEnd ;========================================================================== ; These hotkey functions only do something if called twice within a ; specified time ($DOUBLE_CLICK_TIME) ;========================================================================== Func do_ctrl_w() ;Declare vars Static $iPrevTime = 0 Local $iCurrTime = TimerDiff($ghCtrlWTimer) ;If function called twice within specified time If $iCurrTime < ($iPrevTime + $DOUBLE_CLICK_TIME) Then ;Do something MsgBox($MB_ICONINFORMATION, "INFO", "CTRL+W double click occurred.") ;Reset timer $ghCtrlWTimer = TimerInit() EndIf ;Reset previous Time to current time $iPrevTime = TimerDiff($ghCtrlWTimer) EndFunc Func do_ctrl_j() ;Declare vars Static $iPrevTime = 0 Local $iCurrTime = TimerDiff($ghCtrlJTimer) ;If function called twice within specified time If $iCurrTime < ($iPrevTime + $DOUBLE_CLICK_TIME) Then ;Do something MsgBox($MB_ICONINFORMATION, "INFO", "CTRL+J double click occurred.") ;Reset timer $ghCtrlJTimer = TimerInit() EndIf ;Reset previous Time to current time $iPrevTime = TimerDiff($ghCtrlJTimer) EndFunc Edited September 26 by TheXman pixelsearch, argumentum, Dan_555 and 2 others 5 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
pixelsearch Posted September 27 Share Posted September 27 (edited) Hello everybody When using HotKeys, I like to deactivate them immediately as 1st instruction at the beginning of the function, then reactivate them at the very end of the function. If you don't do that, then be prepared to watch the Hotkey triggered several times if you keep the keys pressed just a bit too long. So I made some changes to @TheXman good script, to add this functionality. You can try it for example like this : * Open NotePäd and type anything in it * Run the script below (the hotkey is Ctrl+a (not the best hotkey but good for the test) then select the NotePad window. * OP's behavior seems to be respected by the script (the mimic of the "double click" on Ctrl+a) * If the 1st line of the function is... HotKeySet("^a") ... then a "long" press on Ctrl+a will select what you typed in NotePad. Is it a good behavior to have it selected ? I'm not sure as you could still select all by using NotePad menu. * If the 1st line of the function is... HotKeySet("^a", _DoNothing) ...then a long press on Ctrl+a will not select what you typed in NotePad. Also please note that while the informative MsgBox is displayed during the HotKey function, then a couple of press on Ctrl+a would indeed buffer the keys (as MsgBox is a blocking function) but they won't be processed with this rewrited script, no matter the 1st line of the function is HotKeySet("^a") or HotKeySet("^a", _DoNothing) Of course the question could be : "why should the user press for a long time Ctrl+a when a MsgBox is displayed ?" The answer could be : "just to test !" * The following added part of code should prevent Ctrl+a to be processed when we're inside the HotKey function, in case the user keeps Ctrl+a pressed a "long" time : While _IsPressed("11", $ghUserDll) And _IsPressed("41", $ghUserDll) ; Ctrl = 11, A = 41 Sleep(10) WEnd * I added a Sleep(10) in main loop to refresh the CPU * The counter $iCounter is just here to indicate how many times the HotKey function was accessed, so we can see in real time its increment in the Console while pressing this or that. expandcollapse popup#include <Misc.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration ;Declare constants Const $DOUBLE_CLICK_TIME = 500 ;Declare global vars Global $ghUserDll = DllOpen("user32.dll"), $ghCtrl_ATimer = TimerInit() ;Set hotkey HotKeySet("^a", do_ctrl_a) ;Loop until ESC pressed While 1 If _IsPressed("1B", $ghUserDll) then ExitLoop Sleep(10) WEnd ;========================================================================== ; This hotkey function only do something if called twice ; within a specified time ($DOUBLE_CLICK_TIME) ;========================================================================== Func do_ctrl_a() ; HotKeySet("^a") HotKeySet("^a", _DoNothing) While _IsPressed("11", $ghUserDll) And _IsPressed("41", $ghUserDll) ; Ctrl = 11, A = 41 Sleep(10) WEnd Local Static $iCounter = 0 $iCounter += 1 ConsoleWrite($iCounter & " ") ;Declare vars Local Static $iPrevTime = 0 Local $iCurrTime = TimerDiff($ghCtrl_ATimer) ;If function called twice within specified time If $iCurrTime < ($iPrevTime + $DOUBLE_CLICK_TIME) Then ;Do something MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), "INFO", "CTRL+A double click occurred.") ;Reset timer $ghCtrl_ATimer = TimerInit() EndIf ;Reset previous Time to current time $iPrevTime = TimerDiff($ghCtrl_ATimer) HotKeySet("^a", do_ctrl_a) EndFunc ;============================================== Func _DoNothing() EndFunc ;==>_DoNothing Edited September 27 by pixelsearch typo CYCho 1 Link to comment Share on other sites More sharing options...
TheCrimsonCrusader Posted September 27 Author Share Posted September 27 (edited) Thank you TheXman and pixelsearch, outstanding work! I marked that as the solution. Edited September 27 by TheCrimsonCrusader TheXman 1 Link to comment Share on other sites More sharing options...
pixelsearch Posted September 27 Share Posted September 27 (edited) @TheCrimsonCrusader glad we could help, your wife should be happy There is something important I didn't mention in my preceding post as it was already too long. In real life, you will probably need this Hotkey to be triggered when a specific window is active, but not for any other window. In the example below, Ctrl+a will act normally if the AutoIt help file is active (select all), but if NotePad is active, then the "double-click Ctrl+a+a" will trigger the code you will associate to Ctrl+a+a It means that when any Window is active (except NotePad) then we Send Ctrl+a if the user keys it, also there is code to avoid the very annoying issue of "sticky keys" just before we Send Ctrl+a I tested the script and it seems to work fine. The Window title I used for AutoIt help is "AutoIt Help" (and not "AutoIt Help (v3.3." because if someone tests the script with an older version of AutoIt, then the help file title was simply "AutoIt Help" without any reference to the AutoIt version. Hope it helps. expandcollapse popup#include <MsgBoxConstants.au3> #include <Misc.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration If (Not WinExists("[CLASS:Notepad]")) Or (Not WinExists("AutoIt Help")) Then MsgBox($MB_TOPMOST, "Please do the following for this test", _ "1 - Open NotePad and type something in it" & @crlf & _ "2 - Open AutoIt Help file" & @crlf & @crlf & _ "Then run this script again") Exit EndIf ;Declare constants Const $DOUBLE_CLICK_TIME = 500 ;Declare global vars Global $ghUserDll = DllOpen("user32.dll"), $ghCtrl_ATimer = TimerInit() ;Set hotkey HotKeySet("^a", do_ctrl_a) ;Loop until ESC pressed While 1 If _IsPressed("1B", $ghUserDll) then ExitLoop Sleep(10) WEnd ;========================================================================== ; This hotkey function only do something if called twice ; within a specified time ($DOUBLE_CLICK_TIME) ;========================================================================== Func do_ctrl_a() HotKeySet("^a") While _IsPressed("11", $ghUserDll) And _IsPressed("41", $ghUserDll) ; Ctrl = 11, A = 41 Sleep(10) WEnd Local Static $iCounter = 0 $iCounter += 1 ConsoleWrite($iCounter & " ") If WinActive("[CLASS:Notepad]") Then ;Declare vars Local Static $iPrevTime = 0 Local $iCurrTime = TimerDiff($ghCtrl_ATimer) ;If function called twice within specified time If $iCurrTime < ($iPrevTime + $DOUBLE_CLICK_TIME) Then ;Do something MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), "NOTEPAD INFO", "CTRL+A double click occurred.") ;Reset timer $ghCtrl_ATimer = TimerInit() EndIf ;Reset previous Time to current time $iPrevTime = TimerDiff($ghCtrl_ATimer) Else While _IsPressed("11") ; Ctrl = 11 . Important While to avoid a possible "sticky key" issue before Send("^a") Sleep(10) WEnd Send("^a") EndIf HotKeySet("^a", do_ctrl_a) EndFunc Edited September 27 by pixelsearch typo 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