Sign in to follow this  
Followers 0
myspacee

detect hold down key

4 posts in this topic

hello,

i use my wireless joypad as remote form my media center living room.

I need to turn off pc from joypad (i can set every keyboard button to one joypad button)

So i think to Autoit to detect if a keboard button is hold on for 5 second and then run a script

that turn off my computer. In forum find most of post, speak about simulate a hold key, not detect it.

Anyone can help me ?

thank you,

m.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Thank you for reply,

reading _IsPressed(), write this:

#include <Misc.au3>

dim $counter = 0
HotKeySet("{ESC}","_countdown")

;---------------- MAIN (your script)
while 1
    sleep(100)
WEnd

;---------------- FUNCTION
func _countdown()
    $dll = DllOpen("user32.dll")
    
    While 1
        $counter = $counter + 1
        If _IsPressed("1B", $dll) Then
            tooltip("Cicles : " & $counter)
            Sleep(1000)
            ToolTip("")
            
            if $counter > 100 Then
                msgbox(0,"","run your script after : " & $counter & " cicles")
                $counter = 0
            EndIf
            
        Else
            $counter = 0
            ExitLoop
        EndIf
    WEnd
    DllClose($dll)

EndFunc

Anyone can suggest me corrections ?

thank you,

m.

Edited by myspacee

Share this post


Link to post
Share on other sites

Here is a crude working example.

#include <Misc.au3>
$counter=0
global $counter
  $dll = DllOpen("user32.dll")


while 1
   
       If _IsPressed("25", $dll) Then
           $counter+=0.25
           sleep(250)
           ConsoleWrite("sleeping for "&$counter&@lf)
       Else
           $counter=0
       EndIf
       if $counter=5 Then
         MsgBox(0,"Pressed","For 5 secs",0)
         $counter=0
EndIf        
           
WEnd
DllClose($dll)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0