Sign in to follow this  
Followers 0
OiMunk

Optimizing Key Input sensing?

1 post in this topic

Here's my inefficient code that works, but uses too much CPU. The script senses when the user has started typing, and then continues once they have stopped typing for a period of time.

I'd like to avoid cycling through _IsPressed() calls.

Is there a better way to do this?

#include <Misc.au3>

$dll = DllOpen("user32.dll")
$delay=5000 ;milliseconds since last press
$timer=0

$a=0
While $a=0  ;check for 1st key/mouse press
    for $i = 0x01 to 0x6B

        If _IsPressed($i, $dll) Then
            $a=1    ;trigger exitLoop
        EndIf
    Next
    
    Sleep(20)
Wend

While 1           ; verify that keys are still being pressed
    for $i = 0x01 to 0x6B

        If _IsPressed($i, $dll) Then
            $timer=0
        EndIf
    Next
    
    $timer+=1
    Sleep(20)

    if $timer > $delay/23 Then; 23=compensated for processing time + sleep
        ExitLoop
    EndIf

Wend

OtherFunctions()

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