Jump to content

A better way to write the following script


Recommended Posts

maybe I've just not had the right code, as I said above I'm an autoit n00b, but I've had intermittent results using the ispressed function to detect keystrokes in a while loop. that's why I suggested hotkeypress. if ispressed can detect the key, shouldn't hotkeypress be able to?

is the select case method faster than the if then method? I am sure the length of time the key is pressed is what causes the if statements to miss the keypress.

for example the following does not capture the keypress most of the time.

#include<misc.au3>

while 1
    sleep(10000)
    $test=_IsPressed("41")
    sleep(100)
    ConsoleWrite("                   "&$test)
WEnd

but this does more often (less sleep time, or in the case of many if statements just the time it takes to execute code)

#include<misc.au3>

while 1
;   sleep(10000)
    $test=_IsPressed("41")
    sleep(100)
    ConsoleWrite("                   "&$test)
WEnd

this even more often

#include<misc.au3>

while 1
;   sleep(10000)
    $test=_IsPressed("41")
;~   sleep(100)
    ConsoleWrite("                   "&$test&@LF)
WEnd

but this always detects the key

hotkeyset("a","test")
while 1
    sleep(100)
WEnd

func test()
    msgbox(0,"","'a' was pressed")
EndFunc

the code I posted was an example, not a complete script for you to test. on that note, is that what is expected from a response with code in it? a completely written script for the OP to test?

I don't want to post if I'm not following expectations.

Edited by DangerousDan
Link to comment
Share on other sites

  • Replies 65
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Something like this ? :)

Opt("SendKeyDelay", 30)
Opt("SendKeyDownDelay", 5)
;Please uncomment   #Include <Misc.au3> if you use #include <IsPressed.au3>
;#include <IsPressed_UDF.au3>
#include <Misc.au3>

ClipPut('')

While 1
    If _IsPressed('91') Then
        _Command("AbuseLang")
    ElseIf _IsPressed('13') Then
        _Command("FoulLang")
    ElseIf _IsPressed('2D') Then
        _Command("BadSpray")
    ElseIf _IsPressed('2E') Then
        _Command("BadName")
    ElseIf _IsPressed('24') Then
        _Command("AbuseKick")
    ElseIf _IsPressed('21') Then
        _Command("FoulKick")
    ElseIf _IsPressed('22') Then
        _Command("SprayKick")
    ElseIf _IsPressed('23') Then
        _Command("NameKick")
    EndIf
    Sleep(20)
WEnd

Func _Command($what)
    $PlayerName = ClipGet()
    ;Warnings Below
    Switch $what
        Case "AbuseLang"
            Send('y@ ' & $PlayerName & ', Please watch your language on our servers. Thanks.', 1)
        Case "FoulLang"
            Send('y@ ' & $PlayerName & ', Please keep inappropiate content off of our servers. Thank you.', 1)
        Case "BadSpray"
            Send('u@@ ' & $PlayerName & ', Please do not spray your spray again in our servers. Thank you.', 1)
        Case "BadName"
            Send('u@@ ' & $PlayerName & ', Please change your name, as <these words> are not allowed on our servers. Thank you.', 1)
        Case "AbuseKick"
            Send('sm_kick ' & $PlayerName & ' "Repeated use of foul/abusive language"', 1)
        Case "FoulKick"
            Send('sm_kick ' & $PlayerName & ' "Repeated use of inappropiate language"', 1)
        Case "SprayKick"
            Send('sm_kick <' & $PlayerName & '> "Inappropiate spray"', 1)
        Case "NameKick"
            Send('sm_kick <' & $PlayerName & '> "Inappropiate name"', 1)
    EndSwitch
EndFunc

[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Link to comment
Share on other sites

Talk about the blind leading the blind on this one! :)

Here's an elegant way to do it, without using hideous repeated If-ElseIf-EndIfs or hammering _IsPressed.

;----- Choose HotKeys here -----
; Change the hotkeys to whatever you wantthem to be (see helpfile)
Global $aHotKeys[9]
$aHotKeys[1] = "{F1}";AbuseLang
$aHotKeys[2] = "{F2}";FoulLang
$aHotKeys[3] = "{F3}";BadSpray
$aHotKeys[4] = "{F4}";BadName

$aHotKeys[5] = "{F5}";AbuseKick
$aHotKeys[6] = "{F6}";FoulKick
$aHotKeys[7] = "{F7}";SpayKick
$aHotKeys[8] = "{F8}";NameKick

;----- Assign HotKeys -----
For $i = 1 to (UBound($aHotKeys) - 1)
    HotKeySet($aHotKeys[$i],"HotKeyPressed")
Next

;===== LOOP =====
While 1
    Sleep(100)
WEnd

;----- Commands to send after HotKey pressed -----
Func HotKeyPressed()
    
    Local $sPlayerName = ClipGet()
    
    Switch @HotKeyPressed
        Case $aHotKeys[1];AbuseLang
            Send('y@ ' & $sPlayerName & ', Please watch your language on our servers. Thanks.', 1)
        Case $aHotKeys[2];FoulLang
            Send('y@ ' & $sPlayerName & ', Please keep inappropiate content off of our servers. Thank you.', 1)
        Case $aHotKeys[3];BadSpray
            Send('y@ ' & $sPlayerName & ', Please do not spray your spray again in our servers. Thank you.', 1)
        Case $aHotKeys[4];BadName
            Send('y@ ' & $sPlayerName & ', Please change your name, as <these words> are not allowed on our servers. Thank you.', 1)
            
        Case $aHotKeys[5];AbuseKick
            Send('sm_kick ' & $sPlayerName & ' "Repeated use of foul/abusive language"', 1)
        Case $aHotKeys[6];FoulKick
            Send('sm_kick ' & $sPlayerName & ' "Repeated use of inappropiate language"', 1)
        Case $aHotKeys[7];SpayKick
            Send('sm_kick ' & $sPlayerName & ' "Inappropiate spray"', 1)
        Case $aHotKeys[8];NameKick
            Send('sm_kick ' & $sPlayerName & ' "Inappropiate name"', 1)
    EndSwitch

EndFunc
Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

You can if you read the helpfile

;----- Choose HotKeys here -----
; Change the hotkeys to whatever you want them to be (see helpfile)
Global $aHotKeys[9]
$aHotKeys[1] = "{F1}";AbuseLang
$aHotKeys[2] = "{F2}";FoulLang
$aHotKeys[3] = "{F3}";BadSpray
$aHotKeys[4] = "{F4}";BadName

$aHotKeys[5] = "{F5}";AbuseKick
$aHotKeys[6] = "{F6}";FoulKick
$aHotKeys[7] = "{F7}";SpayKick
$aHotKeys[8] = "{F8}";NameKick

;----- Assign HotKeys -----
For $i = 1 to (UBound($aHotKeys) - 1)
    HotKeySet($aHotKeys[$i],"HotKeyPressed")
Next

;===== LOOP =====
While 1
    Sleep(100)
WEnd

;----- Commands to send after HotKey pressed -----
Func HotKeyPressed()
    
    Local $sPlayerName = ClipGet()
    
;----- allow normal use of key used for hotkey -----
    HotKeySet(@HotKeyPressed)
    Send(@HotKeyPressed)
    HotKeySet(@HotKeyPressed,"HotKeyPressed")
    
    Switch @HotKeyPressed
        Case $aHotKeys[1];AbuseLang
            Send('y@ ' & $sPlayerName & ', Please watch your language on our servers. Thanks.', 1)
        Case $aHotKeys[2];FoulLang
            Send('y@ ' & $sPlayerName & ', Please keep inappropiate content off of our servers. Thank you.', 1)
        Case $aHotKeys[3];BadSpray
            Send('y@ ' & $sPlayerName & ', Please do not spray your spray again in our servers. Thank you.', 1)
        Case $aHotKeys[4];BadName
            Send('y@ ' & $sPlayerName & ', Please change your name, as <these words> are not allowed on our servers. Thank you.', 1)
            
        Case $aHotKeys[5];AbuseKick
            Send('sm_kick ' & $sPlayerName & ' "Repeated use of foul/abusive language"', 1)
        Case $aHotKeys[6];FoulKick
            Send('sm_kick ' & $sPlayerName & ' "Repeated use of inappropiate language"', 1)
        Case $aHotKeys[7];SpayKick
            Send('sm_kick ' & $sPlayerName & ' "Inappropiate spray"', 1)
        Case $aHotKeys[8];NameKick
            Send('sm_kick ' & $sPlayerName & ' "Inappropiate name"', 1)
    EndSwitch

EndFunc

[EDIT] removed some debug script

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

1) read the helpfile:

HOTKEYSET

; capture and pass along a keypress

HotKeySet("{Esc}", "captureEsc")

Func captureEsc()

; ... can do stuff here

HotKeySet("{Esc}")

Send("{Esc}")

HotKeySet("{Esc}", "captureEsc")

EndFunc

2) look at the change made to the second script i posted to take this into account:

.....
;----- allow normal use of key used for hotkey -----
    HotKeySet(@HotKeyPressed)
    Send(@HotKeyPressed)
    HotKeySet(@HotKeyPressed,"HotKeyPressed")
.....
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

@fctd

Its almost the same thing I wrote .... :)

Cheers, FireFox.

Thats right Firefox, but that's the question ! (A better way to write the following script)

What is better ????

This???

Opt("SendKeyDelay", 30)
Opt("SendKeyDownDelay", 5)
;Please uncomment   #Include <Misc.au3> if you use #include <IsPressed.au3>
;#include <IsPressed_UDF.au3>
#include <Misc.au3>

ClipPut('')

While 1
    Select
        Case _IsPressed('91')
            _Command("AbuseLang")
        Case _IsPressed('13')
            _Command("FoulLang")
        Case _IsPressed('2D')
            _Command("BadSpray")
        Case _IsPressed('2E')
            _Command("BadName")
        Case _IsPressed('24')
            _Command("AbuseKick")
        Case _IsPressed('21')
            _Command("FoulKick")
        Case _IsPressed('22')
            _Command("SprayKick")
        Case _IsPressed('23')
            _Command("NameKick")
    EndSelect
    Sleep(20)
WEnd

Func _Command($what)
    $PlayerName = ClipGet()
    ;Warnings Below
    Switch $what
        Case "AbuseLang"
            Send('y@ ' & $PlayerName & ', Please watch your language on our servers. Thanks.', 1)
        Case "FoulLang"
            Send('y@ ' & $PlayerName & ', Please keep inappropiate content off of our servers. Thank you.', 1)
        Case "BadSpray"
            Send('u@@ ' & $PlayerName & ', Please do not spray your spray again in our servers. Thank you.', 1)
        Case "BadName"
            Send('u@@ ' & $PlayerName & ', Please change your name, as <these words> are not allowed on our servers. Thank you.', 1)
        Case "AbuseKick"
            Send('sm_kick ' & $PlayerName & ' "Repeated use of foul/abusive language"', 1)
        Case "FoulKick"
            Send('sm_kick ' & $PlayerName & ' "Repeated use of inappropiate language"', 1)
        Case "SprayKick"
            Send('sm_kick <' & $PlayerName & '> "Inappropiate spray"', 1)
        Case "NameKick"
            Send('sm_kick <' & $PlayerName & '> "Inappropiate name"', 1)
    EndSwitch
EndFunc

There are different ways to write code, but what is the best one?

What does AgentSmith15 want?

[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Link to comment
Share on other sites

that's what I am pointing out, hotkeyset is much more efficient for this application if the program he is trying to use does not supersede all hotkeyset commands. ispressed WILL require the user hold down the key until the action is taken. hotkeyset will immediately run the function, regardless of where in the while loop the program is. if you miss an ispressed if statement you have to hold the key down until it returns to this statement or the keypress is not detected. see the examples I have posted. using an array is an even more efficient way of doing it, nice addition;)

read the help file, for sure, on hotkeyset. even if you don't want/have to pass the hotkey's to any other program you have more than one choice to use hotkeyset. I am using the title of the window to enable or disable hotkeys in a while loop. it's still not bulletproof, you have to wait for the loop to determine the window has changed each time, since more than one window is applicable for the app I wrote I can't just set keys to press when I don't need them in the affected applications but still need them available in other running applications.

Thats right Firefox, but that's the question ! (A better way to write the following script)

What is better ????

This???

Opt("SendKeyDelay", 30)
Opt("SendKeyDownDelay", 5)
;Please uncomment   #Include <Misc.au3> if you use #include <IsPressed.au3>
;#include <IsPressed_UDF.au3>
#include <Misc.au3>

ClipPut('')

While 1
    Select
        Case _IsPressed('91')
            _Command("AbuseLang")
        Case _IsPressed('13')
            _Command("FoulLang")
        Case _IsPressed('2D')
            _Command("BadSpray")
        Case _IsPressed('2E')
            _Command("BadName")
        Case _IsPressed('24')
            _Command("AbuseKick")
        Case _IsPressed('21')
            _Command("FoulKick")
        Case _IsPressed('22')
            _Command("SprayKick")
        Case _IsPressed('23')
            _Command("NameKick")
    EndSelect
    Sleep(20)
WEnd

Func _Command($what)
    $PlayerName = ClipGet()
    ;Warnings Below
    Switch $what
        Case "AbuseLang"
            Send('y@ ' & $PlayerName & ', Please watch your language on our servers. Thanks.', 1)
        Case "FoulLang"
            Send('y@ ' & $PlayerName & ', Please keep inappropiate content off of our servers. Thank you.', 1)
        Case "BadSpray"
            Send('u@@ ' & $PlayerName & ', Please do not spray your spray again in our servers. Thank you.', 1)
        Case "BadName"
            Send('u@@ ' & $PlayerName & ', Please change your name, as <these words> are not allowed on our servers. Thank you.', 1)
        Case "AbuseKick"
            Send('sm_kick ' & $PlayerName & ' "Repeated use of foul/abusive language"', 1)
        Case "FoulKick"
            Send('sm_kick ' & $PlayerName & ' "Repeated use of inappropiate language"', 1)
        Case "SprayKick"
            Send('sm_kick <' & $PlayerName & '> "Inappropiate spray"', 1)
        Case "NameKick"
            Send('sm_kick <' & $PlayerName & '> "Inappropiate name"', 1)
    EndSwitch
EndFunc

There are different ways to write code, but what is the best one?

What does AgentSmith15 want?

Link to comment
Share on other sites

while 1

if winactive("yourapp","") then

hotkeyset("key","func");to set hotkey

else

hotkeyset("key");to unset hotkey

endif

wend

if you tab to another app, the hotkey is unset. if you are in your app, the hotkey is not passed to the app when you use it.

Edited by DangerousDan
Link to comment
Share on other sites

So a summary of all code's. :)

Thanks to DangerousDan, andybiochem and FireFox.

Should this be the best way to write the script?

;----- Choose HotKeys here -----
; Change the hotkeys to whatever you wantthem to be (see helpfile)
Global $aHotKeys[9]
$aHotKeys[1] = "{F1}";AbuseLang
$aHotKeys[2] = "{F2}";FoulLang
$aHotKeys[3] = "{F3}";BadSpray
$aHotKeys[4] = "{F4}";BadName

$aHotKeys[5] = "{F5}";AbuseKick
$aHotKeys[6] = "{F6}";FoulKick
$aHotKeys[7] = "{F7}";SpayKick
$aHotKeys[8] = "{F8}";NameKick

;----- Assign HotKeys -----
For $i = 1 to (UBound($aHotKeys) - 1)
    HotKeySet($aHotKeys[$i],"HotKeyPressed")
Next

;===== LOOP =====
While 1
    Sleep(100)
WEnd


;----- Commands to send after HotKey pressed -----
Func HotKeyPressed()
    
    Local $sPlayerName = ClipGet()
    
    If winactive("YoureApp", "") Then
        Switch @HotKeyPressed
            Case $aHotKeys[1];AbuseLang
                Send('y@ ' & $sPlayerName & ', Please watch your language on our servers. Thanks.', 1)
            Case $aHotKeys[2];FoulLang
                Send('y@ ' & $sPlayerName & ', Please keep inappropiate content off of our servers. Thank you.', 1)
            Case $aHotKeys[3];BadSpray
                Send('y@ ' & $sPlayerName & ', Please do not spray your spray again in our servers. Thank you.', 1)
            Case $aHotKeys[4];BadName
                Send('y@ ' & $sPlayerName & ', Please change your name, as <these words> are not allowed on our servers. Thank you.', 1)
            Case $aHotKeys[5];AbuseKick
                Send('sm_kick ' & $sPlayerName & ' "Repeated use of foul/abusive language"', 1)
            Case $aHotKeys[6];FoulKick
                Send('sm_kick ' & $sPlayerName & ' "Repeated use of inappropiate language"', 1)
            Case $aHotKeys[7];SpayKick
                Send('sm_kick ' & $sPlayerName & ' "Inappropiate spray"', 1)
            Case $aHotKeys[8];NameKick
                Send('sm_kick ' & $sPlayerName & ' "Inappropiate name"', 1)
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed) 
        HotKeySet(@HotKeyPressed,"HotKeyPressed")
    EndIf
EndFunc

Just one question:

Why does the AutoIt icon's in the system tray increase when the application is not active ?

[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Link to comment
Share on other sites

@fctd

There isnt best way to write something in autoit if all solutions works...

you can do test time for take the speedest script or take the one you prefer :)

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

@fctd

There isnt best way to write something in autoit if all solutions works...

you can do test time for take the speedest script or take the one you prefer :o

Cheers, FireFox.

I'm 100% agree. :)

Greetings.

[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Link to comment
Share on other sites

Just one question:

Why does the AutoIt icon's in the system tray increase when the application is not active ?

Bugs I think, this happens on my system too. Hovering the mouse over the icons makes them dissappear.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

this is normal because when your script is closed (Autoit3.exe) then you have the mouse for clicking to taskbar arrow for refresh icons and make your script icon disapears but sometimes it doesnt work... I cant explain it more so if anyone have something better to say, I will read it :)

Cheers, FireFox.

Link to comment
Share on other sites

Talk about the blind leading the blind on this one! :)

Here's an elegant way to do it, without using hideous repeated If-ElseIf-EndIfs or hammering _IsPressed.

;----- Choose HotKeys here -----
; Change the hotkeys to whatever you wantthem to be (see helpfile)
Global $aHotKeys[9]
$aHotKeys[1] = "{F1}";AbuseLang
$aHotKeys[2] = "{F2}";FoulLang
$aHotKeys[3] = "{F3}";BadSpray
$aHotKeys[4] = "{F4}";BadName

$aHotKeys[5] = "{F5}";AbuseKick
$aHotKeys[6] = "{F6}";FoulKick
$aHotKeys[7] = "{F7}";SpayKick
$aHotKeys[8] = "{F8}";NameKick

;----- Assign HotKeys -----
For $i = 1 to (UBound($aHotKeys) - 1)
    HotKeySet($aHotKeys[$i],"HotKeyPressed")
Next

;===== LOOP =====
While 1
    Sleep(100)
WEnd

;----- Commands to send after HotKey pressed -----
Func HotKeyPressed()
    
    Local $sPlayerName = ClipGet()
    
    Switch @HotKeyPressed
        Case $aHotKeys[1];AbuseLang
            Send('y@ ' & $sPlayerName & ', Please watch your language on our servers. Thanks.', 1)
        Case $aHotKeys[2];FoulLang
            Send('y@ ' & $sPlayerName & ', Please keep inappropriate content off of our servers. Thank you.', 1)
        Case $aHotKeys[3];BadSpray
            Send('y@ ' & $sPlayerName & ', Please do not spray your spray again in our servers. Thank you.', 1)
        Case $aHotKeys[4];BadName
            Send('y@ ' & $sPlayerName & ', Please change your name, as <these words> are not allowed on our servers. Thank you.', 1)
            
        Case $aHotKeys[5];AbuseKick
            Send('sm_kick ' & $sPlayerName & ' "Repeated use of foul/abusive language"', 1)
        Case $aHotKeys[6];FoulKick
            Send('sm_kick ' & $sPlayerName & ' "Repeated use of inappropriate language"', 1)
        Case $aHotKeys[7];SpayKick
            Send('sm_kick ' & $sPlayerName & ' "Inappropriate spray"', 1)
        Case $aHotKeys[8];NameKick
            Send('sm_kick ' & $sPlayerName & ' "Inappropriate name"', 1)
    EndSwitch

EndFunc

Elegant Indeed...

But the game I am using doesn't recognize hotkeys set by other applications, and it only seems to work with IsPressed().

Link to comment
Share on other sites

maybe I've just not had the right code, as I said above I'm an autoit n00b, but I've had intermittent results using the ispressed function to detect keystrokes in a while loop. that's why I suggested hotkeypress. if ispressed can detect the key, shouldn't hotkeypress be able to?

is the select case method faster than the if then method? I am sure the length of time the key is pressed is what causes the if statements to miss the keypress.

for example the following does not capture the keypress most of the time.

#include<misc.au3>

while 1
    sleep(10000)
    $test=_IsPressed("41")
    sleep(100)
    ConsoleWrite("                   "&$test)
WEnd

but this does more often (less sleep time, or in the case of many if statements just the time it takes to execute code)

#include<misc.au3>

while 1
;   sleep(10000)
    $test=_IsPressed("41")
    sleep(100)
    ConsoleWrite("                   "&$test)
WEnd

this even more often

#include<misc.au3>

while 1
;   sleep(10000)
    $test=_IsPressed("41")
;~   sleep(100)
    ConsoleWrite("                   "&$test&@LF)
WEnd

but this always detects the key

hotkeyset("a","test")
while 1
    sleep(100)
WEnd

func test()
    msgbox(0,"","'a' was pressed")
EndFunc

the code I posted was an example, not a complete script for you to test. on that note, is that what is expected from a response with code in it? a completely written script for the OP to test?

I don't want to post if I'm not following expectations.

Cannot use the hotkeyset so that script is ruled out. But the 3rd example has no pauses, so the CPU is going to get hammered to detect a keypress.

10 seconds is a long time for a pause, but I figure anywhere from 20 to 200 milliseconds is a okay amount.

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...