Sign in to follow this  
Followers 0
divadnivip007

_IsPressed Problem

5 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

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

Share this post


Link to post
Share on other sites

Great script. Could it be changed so I don't have to hold down "F2"? I would like to send a different number every time I presses "F2" and make a infinite loop for it.

Thx

Dave

Share this post


Link to post
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

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

Share this post


Link to post
Share on other sites

It works perfectly!

Thx a lot Boththose!!

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