Jump to content

_IsPressed Problem


Recommended Posts

Hey,

First I am a newb with AutoIt. I've tried to do it by myself but I cannot figure how to manage the function "If is pressed again".

Is there a way to do something like this:

If "F2" is pressed then send "1"

If "F2" is pressed again then send "2"

If "F2" is pressed again send "1"

If "F2" is pressed again then send "2"

Here is my script so far:

While 1

If _IsPressed("71") = 1 Then ;IF F2 is pressed

Send("{1}") ; Send 1

Thx a lot

Dave

Link to comment
Share on other sites

give your ispressed if statement other criteria to determine the 1 or the 2. This should alternate 1 and 2 as you hold down F2...

#Include <Misc.au3>



$flag = 0

while 1

If _ispressed(71) And $flag = 1 Then
    send ("2")
    $flag = 0
    

elseif _ispressed(71) And $flag <> 1 Then
    send ("1")
    $flag = 1
    Endif
    
sleep (100)

Wend
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

This is probably better anyway.

hotkeyset("{F2}" , "one")

Func one()
    send ("1")
hotkeyset("{F2}" , "two")
EndFunc

Func two()
    send ("2")
hotkeyset("{F2}" , "one")
EndFunc


while 1

sleep (5)

Wend

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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