Jump to content

HotKeySet + {key down}/{key up}?


Recommended Posts

I need to measure the interval between key up and key down. I tried to do it with 2 hotkeysets ( {key down}/{key up}) pointing to 2 different functions. HotKeySet, however, seems not to work with {key down}/{key up} as hotkeys, so any suggestions what should I fo?

Link to comment
Share on other sites

This is like really experimental (just to see how things work) and written on the small hours, that's why I prefered to rather describe the problem. I didn't even take time to think whether this acctually measures time or not, before I ran into this hotkeyset problem :)

-And rawrr, I didn't mean the arrow keys, I meant any key. To measure the time the key was held down.

HotKeySet("{F11}", "test2")
HotKeySet("{a down}", "ad")
HotKeySet("{a up}", "au")
HotKeySet("{d down}", "dd")
HotKeySet("{d up}", "du")
Global $roska
Global $dif

Func test2()
    Send ("{w down}")
    Global $begin = TimerInit()
    HotKeySet("{F11}", "stop")
EndFunc

Func ad()
InputBox ( "title", "Prompt", $roska)
    $dif = Round(TimerDiff($begin))
    $roska = $roska & $dif & " a("
Endfunc


Func au()
    $roska = $roska & Round(TimerDiff($begin)) - $dif & ") "
    $begin = TimerInit()
Endfunc


Func dd()
    $dif = Round(TimerDiff($begin))
    $roska = $roska & $dif & " d("
Endfunc


Func du()
    $roska = $roska & Round(TimerDiff($begin)) - $dif & ") "
    $begin = TimerInit()
Endfunc

Func stop()
    $roska = $roska & TimerDiff($begin)
    Send ("{w up}")
    InputBox ( "title", "Prompt", $roska)
    HotKeySet("{F11}", "test2")
    $roska = ""
    $dif = ""
EndFunc

Sleep(10000)
While 1 = 1
Wend
Edited by obd
Link to comment
Share on other sites

Something like...Tested

#include<Misc.au3>
If _IsPressed("01") Then
    $Timer=TimerInit()
    While _IsPressed("01")
        Sleep(1)
    WEnd
    $Time=Round(TimerDiff($Timer))
    MsgBox(0,"Time(ms) button held",$Time)
EndIf
Link to comment
Share on other sites

HotKeySet("{d up}", "du")
{xxx up}, {xxx down} are for send. They don't work on HotKeySet. HotKeySet triggers when the key combo is released.

Generator's code is the correct way, but the code has to be in a loop.

Link to comment
Share on other sites

The keyboard has a repeat delay and a repeat rate. This sript will work but your accuracy is limited by the repeat delay.

Dim $diff, $i, $pole=0, $down=0
HotKeySet("a","ad")

While 1
WEnd

Func ad()
    $i=TimerInit()
    If $down=1 Then Return
    HotKeySet("a","up")
    $begin=TimerInit()
While $pole<500; < Must be greater than keyboard repeat delay
    $pole=TimerDiff($i)
WEnd
    $diff=TimerDiff($begin)
    MsgBox(0,$pole,$diff)
    HotKeySet("a","ad")
$down=0
$pole=0
EndFunc

Func up()
$i=TimerInit()
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...