AutoHotkey Community

It is currently May 25th, 2012, 10:37 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: February 24th, 2007, 3:04 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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 February 24th, 2007, 4:43 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2007, 5:06 am 
Fantastic!!!!
Thank you very much!!!! :D :D :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2007, 4:14 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Fixed in the original post the key hold time, not to include key-up time. It is more accurate now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2007, 4:27 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Superb Laszlo, thank you very much !

I tried with LButton and timout=150 which seems more natural

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2008, 12:08 am 
Wow. Very useful script!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2008, 3:53 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2008, 4:49 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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 \~, \+, \>.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Can someone explain
PostPosted: January 20th, 2008, 7:45 pm 
Hi guys,

can someone explain, where we could use this script?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2008, 9:56 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Thank you a lot. I've implemented it in RapidHotkey()

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2008, 7:33 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
This could add a lot of functionality to keyboards. Now I can double click any key I want :D

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: tidbit, toddintr and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group