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 

triple press, problem with "send"

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
elchapin



Joined: 06 Mar 2007
Posts: 64
Location: Columbus, OH, USA

PostPosted: Tue Aug 21, 2007 4:41 pm    Post subject: triple press, problem with "send" Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Tue Aug 21, 2007 5:02 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
tonne



Joined: 06 Jun 2006
Posts: 1651
Location: Denmark

PostPosted: Tue Aug 21, 2007 5:23 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
elchapin



Joined: 06 Mar 2007
Posts: 64
Location: Columbus, OH, USA

PostPosted: Tue Aug 21, 2007 5:26 pm    Post subject: Reply with quote

@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.
Back to top
View user's profile Send private message Visit poster's website
tonne



Joined: 06 Jun 2006
Posts: 1651
Location: Denmark

PostPosted: Tue Aug 21, 2007 5:39 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
elchapin



Joined: 06 Mar 2007
Posts: 64
Location: Columbus, OH, USA

PostPosted: Tue Aug 21, 2007 5:58 pm    Post subject: Reply with quote

@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.
Back to top
View user's profile Send private message Visit poster's website
Laszlo



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

PostPosted: Tue Aug 21, 2007 6:55 pm    Post subject: Reply with quote

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%_
Back to top
View user's profile Send private message
elchapin



Joined: 06 Mar 2007
Posts: 64
Location: Columbus, OH, USA

PostPosted: Tue Aug 21, 2007 7:43 pm    Post subject: Reply with quote

@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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help 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