 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
180 Guest
|
Posted: Sun May 11, 2008 2:12 am Post subject: Holding down a specific key |
|
|
Could someone please demonstrate function which detects when a key has been held down for any number of seconds, then { does some routine }  |
|
| Back to top |
|
 |
evan Guest
|
Posted: Sun May 11, 2008 2:58 am Post subject: |
|
|
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
|
Posted: Sun May 11, 2008 3:01 am Post subject: |
|
|
You don't need the braces for that. _________________ 1,000 Posts achieved on Saturday April 26, 2008 1:45 am |
|
| Back to top |
|
 |
180 Guest
|
Posted: Sun May 11, 2008 12:56 pm Post subject: |
|
|
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? See what I mean? |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 702
|
Posted: Sun May 11, 2008 10:23 pm Post subject: |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|