Jump to content
Sign in to follow this  
NoMercy

Key Pressed Time

Recommended Posts

NoMercy

hi, 1st of all i`d like to point out that the following program is/will not be used as neither a KeyLogger nor a Game bot.

This program records how long a keyboard button was pressed and saves it to a txt file.

I have made the following code so far.. it is quite accurate but i need more accuracy if possible,

I have also tried playing around with the accuracy but so far 200ms has given me the best results when it comes to more than 10sec of testing time.

for example when i test it with another program for:

30 sec looses 200ms

60 sec looses 800ms

120 sec it actually gained 200ms

This is the other program im testing it with.

Sleep(1000)
Send("{a Down}")
Sleep(10000)       ;<------ Time for how long the key will be pressed.
Send("{a up}")

And this is the code im currently using as my program.

(Note: I currently have only implemented 4 keys to test it with)

$TimePressed = 0
$Accuracy = 200

while 1
    If _IsPressed(41) Then
        $File = FileOpen(@DesktopDir&"\Record.txt", 1) 
        do
            Sleep($Accuracy)
            $TimePressed = $TimePressed + $Accuracy
            $Log = "A : " & $TimePressed &  @CRLF     
        until _IsPressed(41) <> 1
            FileWrite($File, $Log)     
            FileClose($File)
            $TimePressed = 0
    EndIf

    If _IsPressed(42) Then
        $File = FileOpen(@DesktopDir&"\Record.txt", 1) 
        do
            Sleep($Accuracy)
            $TimePressed = $TimePressed + $Accuracy
            $Log = "B : " & $TimePressed &  @CRLF
        Until _IsPressed(57) <> 1
            FileWrite($File, $Log)     
            FileClose($File)
            $TimePressed = 0
    EndIf


    If _IsPressed(43) Then
        $File = FileOpen(@DesktopDir&"\Record.txt", 1) 
        do 
            Sleep($Accuracy)
            $TimePressed = $TimePressed + $Accuracy
            $Log = "C : " & $TimePressed &  @CRLF
        Until _IsPressed(53) <> 1
            FileWrite($File, $Log)     
            FileClose($File)
            $TimePressed = 0
    EndIf


    If _IsPressed(44) Then
        $File = FileOpen(@DesktopDir&"\Record.txt", 1) 
        do
            Sleep($Accuracy)
            $TimePressed = $TimePressed + $Accuracy
            $Log = "D : " & $TimePressed &  @CRLF
        Until _IsPressed(53) <> 1
            FileWrite($File, $Log)     
            FileClose($File)
            $TimePressed = 0
    EndIf
wend


Func _IsPressed($hexKey)        ;Key capture function. Most vital part of the script.
    Local $aR, $bRv
    $hexKey = '0x' & $hexKey
    $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
    If $aR[0] <> 0 Then
        $bRv = 1
    Else
        $bRv = 0
    EndIf
    Return $bRv
EndFunc

I have also tried to do this with the HotkeySet method but didnt have any luck...

Any help would be appreciated.

-Tnx.

Share this post


Link to post
Share on other sites
martin

You could do something like this and get and accuracy of say 20ms

#include <misc.au3>

$accuracy = 20
While 1
    If _IsPressed("41") Then
    $Start = TimerInit()
    While _IsPressed("41")
    Sleep($accuarcy)
    WEnd
    $Log = "A:" & TimerDiff($Start) & @CRLF
    EndIf


WEnd

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
NoMercy

ok this did actually helped alot.

i have rounded it up and now it gives an extra 10-15ms :

A:10010

A:60013

A:120016

added a -10 to the value and now it got:

A:10000

A:60003

A:120005

which i guess is pretty good. now all i need is another program that reads the txt and automatically generates the code for me.

if i have troubles ill post it in a couple of hours... got some work to do now.

Thank you.

Edited by NoMercy

Share this post


Link to post
Share on other sites
NoMercy

If someone has a better more efficient code than this id be more than happy to see it, cus in the long run this program is not as accurate as it might seem.

Thank you.

Share this post


Link to post
Share on other sites
martin

If someone has a better more efficient code than this id be more than happy to see it, cus in the long run this program is not as accurate as it might seem.

Thank you.

How do you know it is inaccurate?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.