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 

Holding down a specific key

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
180
Guest





PostPosted: Sun May 11, 2008 2:12 am    Post subject: Holding down a specific key Reply with quote

Could someone please demonstrate function which detects when a key has been held down for any number of seconds, then { does some routine } Smile
Back to top
evan
Guest





PostPosted: Sun May 11, 2008 2:58 am    Post subject: Reply with quote

a::
{
StartTime := A_TickCount
KeyWait, a
ElapsedTime := A_TickCount - StartTime
msgbox, %ElapsedTime%
}
Back to top
Ian



Joined: 15 Jul 2007
Posts: 1077
Location: Enterprise, Alabama

PostPosted: Sun May 11, 2008 3:01 am    Post subject: Reply with quote

You don't need the braces for that.
_________________
1,000 Posts achieved on Saturday April 26, 2008 1:45 am
Back to top
View user's profile Send private message
180
Guest





PostPosted: Sun May 11, 2008 12:56 pm    Post subject: Reply with quote

Thank you, but can the routine logic actually not wait for the key to be un-pressed for it to calculate duration held down....., but actually go into live routine after a preset number of milliseconds has elapsed even if the person keeps pressing the button down.... whereas only then un-pressing the button would then reset the counter? Smile See what I mean?
Back to top
[VxE]



Joined: 07 Oct 2006
Posts: 702

PostPosted: Sun May 11, 2008 10:23 pm    Post subject: Reply with quote

Code:
a::
If (btiming)
   return
SetTimer, Routine500, -500
SetTimer, Routine3000, -3000
SetTimer, Routine10000, -10000
btiming = 1
return

a up::
SetTimer, Routine500, off
SetTimer, Routine3000, off
SetTimer, Routine10000, off
btiming = 0
return


Routine500:
Routine3000:
Routine10000:
SetFormat, float, 0.1
msgbox % "You have held the `'a`' key for " SubStr( A_ThisLabel, 8 ) / 1000 " seconds."
return

_________________
My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   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