| View previous topic :: View next topic |
| Author |
Message |
Laszlo
Joined: 14 Feb 2005 Posts: 4683 Location: Boulder, CO
|
Posted: Sat Feb 24, 2007 3:04 am Post subject: Morse: find hotkey press-and-hold patterns |
|
|
With different hotkey press patterns many more actions can be triggered than just with a hotkey press itself. For example, the key "a" sends "a", two short presses sends "ä", a long press sends "á", and so on. Like Morse codes for different actions.
The following Morse function determines the base key from the current hotkey, and starts monitoring it. If it is released after longer time than timeout (default to 400ms), "1" is appended to the Pattern variable. If the key is released sooner, "0" is appended.
Then the scripts waits for the key to be pressed down again. If it is not pressed within the timeout period, the 0-1 pattern of the last key presses are returned, otherwise the next key hold time will be appended to the Pattern. Usage examples are at the end of the script, for Alt-Z and BackSpace. | Code: | Morse(timeout = 400) { ;
tout := timeout/1000
key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
Loop {
t := A_TickCount
KeyWait %key%
Pattern .= A_TickCount-t > timeout
KeyWait %key%,DT%tout%
If (ErrorLevel)
Return Pattern
}
}
BS::MsgBox % "Morse press pattern " Morse()
!z::
p := Morse()
If (p = "0")
MsgBox Short press
Else If (p = "00")
MsgBox Two short presses
Else If (p = "01")
MsgBox Short+Long press
Else
MsgBox Press pattern %p%
Return |
Edit 20070224: Fixed key hold time, not to include key-up time
Last edited by Laszlo on Sat Feb 24, 2007 4:43 pm; edited 2 times in total |
|
| Back to top |
|
 |
Fantastic!!!! Guest
|
Posted: Sat Feb 24, 2007 5:06 am Post subject: |
|
|
Fantastic!!!!
Thank you very much!!!!  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4683 Location: Boulder, CO
|
Posted: Sat Feb 24, 2007 4:14 pm Post subject: |
|
|
| Fixed in the original post the key hold time, not to include key-up time. It is more accurate now. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4263 Location: Belgrade
|
Posted: Sat Feb 24, 2007 4:27 pm Post subject: |
|
|
Superb Laszlo, thank you very much !
I tried with LButton and timout=150 which seems more natural _________________
 |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Jan 19, 2008 12:08 am Post subject: |
|
|
| Wow. Very useful script! |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Sat Jan 19, 2008 3:53 am Post subject: |
|
|
| Great idea. Though I wouldn't want to use it like in your "a" example. The delay would make normal typing impossible. I guess it would be possible to cook something similar up using Input instead of (or along with) KeyWait that wouldn't get in the way of typing. |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4683 Location: Boulder, CO
|
Posted: Sat Jan 19, 2008 4:49 am Post subject: |
|
|
Input was not used, because (in a loop) it loses keystrokes at fast typing.
You should experience with the settings to fit your style. The “a” example assumes that you never need to type “aa”. If you do, probably a better setup is when a short press time terminates the loop. This way the different replacements only occur after the key “a” was held pressed for a certain time.
I tried many possible ways to enter diacritical letters. For seldom needed characters (like Greek letters) the post-modifier technique was the best for me, because you don’t have to remember their exact invocation. For often used ones I redefined the number keys in the top row of my US keyboard, when ScrollLock is activated. Now the LED sows, which layout is active, and I still have the numbers on the numpad. There are symbols I use moderately often, like ≈, ±, ≥. They get their hotstrings, like \~, \+, \>. |
|
| Back to top |
|
 |
Jefferson Guest
|
Posted: Sun Jan 20, 2008 7:45 pm Post subject: Can someone explain |
|
|
Hi guys,
can someone explain, where we could use this script? |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 2880 Location: AHK Forum
|
|
| Back to top |
|
 |
Frankie
Joined: 02 Nov 2008 Posts: 1066
|
Posted: Sun Dec 14, 2008 7:33 am Post subject: |
|
|
This could add a lot of functionality to keyboards. Now I can double click any key I want  _________________ Click here to join #AHK channel in IRC for general chat and quick help.
Check out my scripts. |
|
| Back to top |
|
 |
|