Disclaimer:
I am new to AutoHotKey and just discovering its potential – WOW! I am very impressed (and overwhelmed) with the possibilities and the complexities. The ingenuity that many of you demonstrate is impressive. I have spent quite a lot of time searching the forum, Reddit, and Superuser to find a way to do what I am wanting but to no avail. Also, I am not adept at any programming language, but I can piddle with code to some degree when given examples.
My intended goal seems simple enough: I want to be able to press and hold down a particular modifier combination, and then effect different actions based on whether I press a certain key stroke once, twice, or even three times WITHOUT releasing the modifier key combination in between. Importantly, each time the modifiers are released, the action would start the sequence over.
An example would be code that will wrap a selected text in single quotes with a single press of the ‘ key while holding down the Ctrl+Alt modifiers. ALTERNATIVELY, it will wrap the selected text in double quotes with a double press of the ‘ key while still holding down the Ctrl+Alt modifiers (without a release of those modifiers in between).
This could then be used in instances of the single key press of the [ key (or the ] key) to wrap in square brackets OR a double press of the [ key (or the ] key) to wrap in curley brackets.
Two other longer-term goals:
1: Be able to cycle through word cases (lower, upper, title) with the same Ctrl+Alt modifier and by clicking a key such as c either once, twice, or three times to result in lower case, upper case, or title case, respectively. Each time it is used and the modifier (Ctrl+Alt) is released, the "state" would return back to the original - in other words, if I select one word and press Ctrl+Alt+c+c the output is to result in upper case. If I then select a different word and press Ctrl+Alt+c the output is to result in lower case. If I then select a different word and press Ctrl+Alt+c the output is to result in lower case. I did find a useful example of code. It is in the archived section of the forum and its subject is, "Trying to Create Shift-F3 Case Changer Like Word".
Author: socrtwo <socrtwo@s2services.com>, "None" and "Lazslo" from the AutoHotKey forum, most of the coding of this script is by "None". See - http://www.autohotkey.com/forum/viewtopic.php?t=55868
The problem I have with that script is that I cannot make it return to "State=0" even though it looks like it should do that with the release of the Shift key. It seems to go through the cycle of invert, upper, lower, title, sentence, in that order regardless of whether the Shift key is released and reheld or not. If I convert to upper case by pressing Shift F3 F3, the next time I change case, the first press of Shift F3 will convert to title case (i.e. the state did not revert back to State=0).
2nd ultimate goal: Be able to cycle through copy, cut, and past with the same modifier held and by hitting another key once, twice, or three times.
Seems like I included a lot in this topic. I thought about separating, but all seemed related.
Thank you in advance,
CBell
Using modifiers and either a single key press or double key press to cycle through actions
Using modifiers and either a single key press or double key press to cycle through actions
Last edited by gregster on 17 Mar 2024, 21:55, edited 1 time in total.
Reason: Topic seems AHK v1-related; hence moved from AHK v2 help (at least for now).
Reason: Topic seems AHK v1-related; hence moved from AHK v2 help (at least for now).
Re: Using modifiers and either a single key press or double key press to cycle through actions
Hallo,
you should include Morse() in your considerations!
The respective Hotkey is used to morse a pattern consisting of “0” (short) and “1” (long).
you should include Morse() in your considerations!
The respective Hotkey is used to morse a pattern consisting of “0” (short) and “1” (long).
Code: Select all
+q:: ; Shift+q
Switch, Morse() {
Case "0":ToolTip, %A_ThisHotkey% once short
Case "00":ToolTip, %A_ThisHotkey% twice short
Case "000":ToolTip, %A_ThisHotkey% thrice short
Case "010":ToolTip, %A_ThisHotkey% short long short
} Return
^!q:: ; Ctrl+Alt+q
Switch, Morse() {
Case "0":ToolTip, %A_ThisHotkey% once short
Case "00":ToolTip, %A_ThisHotkey% twice short
Case "000":ToolTip, %A_ThisHotkey% thrice short
Case "010":ToolTip, %A_ThisHotkey% short long short
} Return
Morse(Timeout = 400) {
Global Pattern := ""
RegExMatch(A_ThisHotkey, "\W$|\w*$", Key)
While, !ErrorLevel {
T := A_TickCount
KeyWait %Key%
Pattern .= A_TickCount-T > Timeout
KeyWait %Key%,% "DT" Timeout/1000
} Return Pattern
}
!Q
@Rohwedder, thank you for this Morse() example. I have used a couple of your morse examples before, but this one is my ah-ha moment.
I think I finally understand what I'm looking at with this example and wow, I am now becoming aware of just how useful this function truly is.
I believe this example should be in the docs regarding hotkeys it is so useful!!
I attempted to find the original Morse(), and found a version by Laszlo that appears to be from 2007.
https://www.autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/
What you presented is modified a bit, so I'm assuming your upgrade touches? So useful!
Many thanks again!!!
I think I finally understand what I'm looking at with this example and wow, I am now becoming aware of just how useful this function truly is.
I believe this example should be in the docs regarding hotkeys it is so useful!!
I attempted to find the original Morse(), and found a version by Laszlo that appears to be from 2007.
https://www.autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/
What you presented is modified a bit, so I'm assuming your upgrade touches? So useful!
Many thanks again!!!
Re: Using modifiers and either a single key press or double key press to cycle through actions
Laszlo's original failed with:(Hold LButton and morse with Q)
I use ~LButton & ... :: if I want to do anything with highlighted text.
Copy, manipulate, look up in Wikipedia, search for files in Everything ...
Code: Select all
~LButton & q:: ; LButton+q
Switch, Morse() {
Case "0":ToolTip, %A_ThisHotkey% once short
Case "00":ToolTip, %A_ThisHotkey% twice short
Case "000":ToolTip, %A_ThisHotkey% thrice short
Case "010":ToolTip, %A_ThisHotkey% short long short
} Return
I use ~LButton & ... :: if I want to do anything with highlighted text.
Copy, manipulate, look up in Wikipedia, search for files in Everything ...
Who is online
Users browsing this forum: Bing [Bot], mstrauss2021, robozao and 238 guests