TheCrimsonCrusader Posted 13 hours ago Share Posted 13 hours ago 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 12 hours ago Share Posted 12 hours ago 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 11 hours ago Share Posted 11 hours ago 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 11 hours ago Author Share Posted 11 hours ago 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 11 hours ago Share Posted 11 hours ago 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...
TheXman Posted 10 hours ago Share Posted 10 hours ago (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 10 hours ago by TheXman Dan_555, argumentum, ioa747 and 1 other 4 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 2 hours ago Share Posted 2 hours ago (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 2 hours ago 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