AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Morse: find hotkey press-and-hold patterns

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4683
Location: Boulder, CO

PostPosted: Sat Feb 24, 2007 3:04 am    Post subject: Morse: find hotkey press-and-hold patterns Reply with quote

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
View user's profile Send private message
Fantastic!!!!
Guest





PostPosted: Sat Feb 24, 2007 5:06 am    Post subject: Reply with quote

Fantastic!!!!
Thank you very much!!!! Very Happy Very Happy Very Happy
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4683
Location: Boulder, CO

PostPosted: Sat Feb 24, 2007 4:14 pm    Post subject: Reply with quote

Fixed in the original post the key hold time, not to include key-up time. It is more accurate now.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 4263
Location: Belgrade

PostPosted: Sat Feb 24, 2007 4:27 pm    Post subject: Reply with quote

Superb Laszlo, thank you very much !

I tried with LButton and timout=150 which seems more natural
_________________
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Jan 19, 2008 12:08 am    Post subject: Reply with quote

Wow. Very useful script!
Back to top
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Sat Jan 19, 2008 3:53 am    Post subject: Reply with quote

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
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4683
Location: Boulder, CO

PostPosted: Sat Jan 19, 2008 4:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Jefferson
Guest





PostPosted: Sun Jan 20, 2008 7:45 pm    Post subject: Can someone explain Reply with quote

Hi guys,

can someone explain, where we could use this script?
Back to top
HotKeyIt



Joined: 18 Jun 2008
Posts: 2880
Location: AHK Forum

PostPosted: Sat Dec 13, 2008 9:56 pm    Post subject: Reply with quote

Thank you a lot. I've implemented it in RapidHotkey()
_________________
AutoHotFile+ToolTip+AutoHotkey_L58H24.dll Wink
Back to top
View user's profile Send private message
Frankie



Joined: 02 Nov 2008
Posts: 1066

PostPosted: Sun Dec 14, 2008 7:33 am    Post subject: Reply with quote

This could add a lot of functionality to keyboards. Now I can double click any key I want Very Happy
_________________
Click here to join #AHK channel in IRC for general chat and quick help.
Check out my scripts.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group