AutoHotkey Community

It is currently May 25th, 2012, 3:22 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: August 21st, 2007, 5:41 pm 
Offline

Joined: March 6th, 2007, 4:35 pm
Posts: 64
Location: Columbus, OH, USA
I am trying to create a hotstring for triple-pressing "d" to insert the date. I want a single press to pass a "d", and a double press to pass a "dd".

I used the script from Help, but I cannot get input to be sent for single-pressing or double-pressing "d".



Code:
SetKeyDelay, -1
SendMode, Input
return

; Example #3: Detection of single, double, and triple-presses of a hotkey. This
; allows a hotkey to perform a different operation depending on how many times
; you press it:



d::
if d_presses > 0 ; SetTimer already started, so we log the keypress instead.
{
  d_presses += 1
  return
}

; Otherwise, this is the first press of a new series. Set count to 1 and start the timer:
d_presses = 1
SetTimer, KeyD, 400 ; Wait for more presses within a 200 millisecond window.
return



KeyD:
SetTimer, KeyD, off
if d_presses = 1 ; The key was pressed once.
   {
     Send, d
   }
else if d_presses = 2 ; The key was pressed twice.
   {
     Send, dd
   }
else if d_presses > 2
   {
     Send, _%A_YYYY%%A_MM%%A_DD%_
   }
   
; Regardless of which action above was triggered, reset the count to prepare for the next series of presses:
d_presses = 0
return


It also seems to continue to log the key presses until there are three, even if I wait several seconds between presses...

I swapped out the "send" lines for "msgbox" and it worked fine then... I am confused! Please help!

_________________
My startup is Telesaur - a telecommuting job site.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 6:02 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Why not just use a hotstring ?
Code:
::ddd::
Send, _%A_YYYY%%A_MM%%A_DD%_
return

Granted that will take effect no matter how slowly you type ddd, but I wouldn't think that would usually be a problem.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 6:23 pm 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
With hotstring options it can be made hotkey-like:
Code:
; * dont need terminator
; ? trigger even inside word
:?*:ddd::
Send, _%A_YYYY%%A_MM%%A_DD%_
return

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 6:26 pm 
Offline

Joined: March 6th, 2007, 4:35 pm
Posts: 64
Location: Columbus, OH, USA
@ManaUser - That's a workable solution... I didn't think of the obvious.

I am still curious about how to do this with key delays though...

_________________
My startup is Telesaur - a telecommuting job site.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 6:39 pm 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
In order to let a script send its own hotkey it must be prefixed with $. It seems that this holds even if the d in your case is sent from a timer!?
Try changing your hotkey to:
Code:
$d::

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 6:58 pm 
Offline

Joined: March 6th, 2007, 4:35 pm
Posts: 64
Location: Columbus, OH, USA
@tonne - I switched "d::" to "$d::", as you suggested, and it worked! Thanks.

I will have to look into the other comment a little more, thanks guys!

_________________
My startup is Telesaur - a telecommuting job site.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 7:55 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The Help just demonstrates the use of timers. For this task you don't need it:
Code:
$~d::
   If (A_ThisHotKey = A_PriorHotKey && A_TimeSincePriorHotKey < 500)
        count++
   Else count = 0
   If (count > 1)
      Send {BS 3}_%A_YYYY%%A_MM%%A_DD%_


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 8:43 pm 
Offline

Joined: March 6th, 2007, 4:35 pm
Posts: 64
Location: Columbus, OH, USA
@Laszlo - Now, that's beautiful! I guess I haven't learned all of the built in variables yet! Thanks!

_________________
My startup is Telesaur - a telecommuting job site.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, engunneer, gemisigo, Google [Bot], rbrtryn, sarevok9, tank, vsub and 16 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