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 

How can I get a key is pressed for 3 seconds?

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





PostPosted: Mon Jun 13, 2005 8:58 am    Post subject: How can I get a key is pressed for 3 seconds? Reply with quote

Hi, I'm Korean
So forgive my English..

At below code the key Numpad0 is the hotkey.
Now I want to modify the script to display a tooltip when the Numpad0 key is pressed for 3 seconds. Otherwise send {Numpad0}
But I don't know how to do...


$Numpad0::Send, {Numpad0}
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3911
Location: Bremen, Germany

PostPosted: Mon Jun 13, 2005 10:00 am    Post subject: Reply with quote

Hi Ifwind,
I'm not very good at hotkeys, but I hope I can direct you into the right direction.
Please have a look at the manual. Look for SetTimer, GetKeyState, EnvSub

MY first guess was:
Code:
$Numpad0:: DownTime = %A_Now%

$Numpad0 UP::
  EnvSub, DownTime, %A_Now% , S
  MsgBox, DownTime = %DownTime%
return
But that didn't work,

So I tried this
Code:
$Numpad0::
  DownTime = %A_Now%
  SetTimer, WatchKey, 100
return

WatchKey:
  Down := GetKeyState(Numpad0)
  If not Down
    {
      UpTime = %A_Now%
      EnvSub, DownTime, %UpTime% , S
      MsgBox, DownTime = %DownTime%
      SetTimer, WatchKey, Off
    }
return
And that didn't work either.

I'm sorry I didn't found a solution for you, but maybe some other user stroles by and points out the mistakes I've made.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Decarlo110



Joined: 15 Dec 2004
Posts: 303
Location: United States

PostPosted: Mon Jun 13, 2005 10:59 am    Post subject: Reply with quote

ifwind, please describe more specifically the result you prefer.
The following are all possibilities:

1) Numpad0 behaves normally in all ways, and tooltip appears after 3 seconds if Numpad0 is still held down.
2) Numpad0 sends Numpad0 once upon release before 3 seconds, but a tooltip appears if Numpad0 is still held down after 3 seconds.
3) Numpad0 sends Numpad0 once upon being pressed, and tooltip appears after 3 seconds if Numpad0 is still held down.
4) Numpad0 auto-repeats while held down until 3 seconds is finished, and then the tooltip appears.
_________________
1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>>
Back to top
View user's profile Send private message
MYYM



Joined: 05 Apr 2005
Posts: 133

PostPosted: Mon Jun 13, 2005 11:09 am    Post subject: Re: How can I get a key is pressed for 3 seconds? Reply with quote

ifwind wrote:
I want to modify the script to display a tooltip when the Numpad0 key is pressed for 3 seconds. Otherwise send {Numpad0}
But I don't know how to do...
$Numpad0::Send, {Numpad0}


I'm not sure if that what you want or not.
anyway it's an idea you can work on it.
Code:
Numpad1::
tt=0 ; set time to 0
loop,100 ; check every 30 ms
{
      GetKeyState, s , Numpad1, p 
   if s=U
   {
      break   
   }
; you can delete the next line it's just to show time running   
Tooltip, %tt% ; show time counter
   tt+=30
   sleep 30
}
if tt<3000  ; if key pressed less than 3 secs
{
      send 1
}
else
{
   Tooltip ,time is more than 3 secs!
   sleep 1000   
}
Tooltip
return
Back to top
View user's profile Send private message Visit poster's website
ifwind
Guest





PostPosted: Mon Jun 13, 2005 12:33 pm    Post subject: Yeh, You know exactly what I want Reply with quote

I just want to know how to do belows

1) Numpad0 behaves normally in all ways, and tooltip appears after 3 seconds if Numpad0 is still held down.
--> Not exactly, but i'm interested in how to do

2) Numpad0 sends Numpad0 once upon release before 3 seconds, but a tooltip appears if Numpad0 is still held down after 3 seconds.
--> This is what i want. Please teach me about it.
Back to top
ifwind
Guest





PostPosted: Mon Jun 13, 2005 12:45 pm    Post subject: Thanks Reply with quote

Thank you, MYYM
It runs very well..
Back to top
Decarlo110



Joined: 15 Dec 2004
Posts: 303
Location: United States

PostPosted: Wed Jun 29, 2005 7:33 pm    Post subject: Reply with quote

ifwind wrote:

1) Numpad0 behaves normally in all ways, and tooltip appears after 3 seconds if Numpad0 is still held down.
--> Not exactly, but i'm interested in how to do


Code:

~Numpad1::
tt=0 ; set time to 0
loop,100 ; check every 30 ms
{
      GetKeyState, s , Numpad1, p 
   if s=U
       Break   
 ; you can delete the next line it's just to show time running   
Tooltip, %tt% ; show time counter
   tt+=30
   sleep 30
}
if tt>3000  ; if key pressed more than 3 secs
{
   Tooltip, time is more than 3 secs!
   sleep 2000
}
Tooltip
return

_________________
1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>>
Back to top
View user's profile Send private message
dk999
Guest





PostPosted: Sat Jun 02, 2007 7:33 pm    Post subject: Delay inbetween commands Reply with quote

Hey i'm trying to create a command so that after a command is played there is a delay (few seconds) before the second command is played
etc : send keyA delay 3s send keyB

Thanks for help from pros Smile
Back to top
rostrus



Joined: 02 Jun 2007
Posts: 9

PostPosted: Sat Jun 02, 2007 8:48 pm    Post subject: Reply with quote

read the help, is very well done!

the command you need is

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