Sign in to follow this  
Followers 0
Ridock

Key Timer?

4 posts in this topic

#1 ·  Posted (edited)

Sorry if this is a re-post. Didnt see if my 1st one went through.

My question is;

Is it possible to tell how long a key has been press for?

I'm using _Ispressed command and $begin = TimerInit(), $dif = TimerDiff($begin)

Thanks for any help.

Edited by Ridock

Share this post


Link to post
Share on other sites



Sorry if this is a re-post. Didnt see if my 1st one went through.

My question is;

Is it possible to tell how long a key has been press for?

I'm using _Ispressed command and $begin = TimerInit(), $dif = TimerDiff($begin)

Thanks for any help.

Yes it's possible, I've shown this before, It was just a very long time ago, and I have no idea what it was for.

#include <Misc.au3>
Global $keytime
While 1
    Sleep(10)
    $keytime = _KeyPressTime('01');01 left mouse click
    If $keytime Then ToolTip('The key / mouse click was held for: ' & $keytime & ' seconds', 0, 0)
WEnd

Func _KeyPressTime($nValue)
    Local $iTimer
    If _IsPressed($nValue) Then
        $iTimer = TimerInit()
        While _IsPressed($nValue)
            Sleep(100)
        WEnd
        Return Round(TimerDiff($iTimer) / 1000, 2)
    EndIf
    Return SetError(1, 0, 0)
EndFunc

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thank you.

What I am trying to do is, be able to map a path in a game by simply recording the the keys and how long they were held for. Then call from a recorded list using those new parameters.

Well hope it works thanks again.

Share this post


Link to post
Share on other sites

Thank you.

What I am trying to do is, be able to map a path in a game by simply recording the the keys and how long they were held for. Then call from a recorded list using those new parameters.

Well hope it works thanks again.

Thats It!!! It was for a game that someone needed to know how long each key was held down for, I'd tell you to look at my posts, but that would take you longer than just coding it yourself :ph34r::lmao:

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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