Jump to content

I'm stuck with while/if loop... please help!


Recommended Posts

#include <Misc.au3>

While 1
   If _IsPressed(59) Then
      Send("{B}")
      MouseDown("left")
   Else
      Send("{B}")
      MouseUp("left")
   EndIf
WEnd

 

I want the script to do this:

- if I press "Y", send "B" once and hold left click down until i release "Y".

- if I take my hands off of "Y" key, then send "B" once again and release left click.

 

but the script I made has problems.

when I run the script, it starts sending "B" repeatedly, and my left click won't work.

 

I'm not smart enough to figure out what the problem is... please help me!

sorry for bad English.

 

Edited by JJ1122
Link to comment
Share on other sites

  • Moderators

@JJ1122 can you give some more information about what you're trying to do? There is almost always an easier way to accomplish things besides sending mouse clicks.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

 

1 hour ago, JLogan3o13 said:

@JJ1122 can you give some more information about what you're trying to do? There is almost always an easier way to accomplish things besides sending mouse clicks.

i want to simplify "press keyboard - press keyboard - click - drag - press keyboard - drop" to "press keyboard - release keyboard".

it's for shopping uses in a korean website.

Link to comment
Share on other sites

5 hours ago, JJ1122 said:

#include <Misc.au3>

While 1
   If _IsPressed(59) Then
      Send("{B}")
      MouseDown("left")
   Else
      Send("{B}")
      MouseUp("left")
   EndIf
WEnd

 

I see that it checks if a button is pressed, if not, it executes Send("{B}") and MouseUp("left").

If...Else...EndIf Example:

If 1+2=8 Then
    MsgBox(0,"","1+2=8 is correct!"&@CRLF _
    &"That's impossible, so you won't see this message.")
Else
    MsgBox(0,"","1+2=8 is NOT correct!")
EndIF



You may want to try this script:
 

#include <Misc.au3>

While 1
    If _IsPressed(59) Then;Checks if button is pressed
      
      ;If button is pressed, it will execute this script:
      Send("{B}")
      MouseDown("left")

      Do
        Sleep(25)
        ;Sleep until button is released.
      Until Not _IsPressed(59)
      
      ;Execute some script if button is released...
      Send("{B}")
      MouseUp("left")

    EndIf

    Sleep(50);It's always a good idea to add Sleep() to avoid using all CPU usage.
WEnd

I haven't tested this script, but I think it should work.

Edited by algiuxas

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

Here is another small example:

#include <Misc.au3>

HotKeySet("{ESC}", "quitter")

$beepFrequency = 300

While True
    If _IsPressed(71) Then
        ConsoleWrite("Started pressing F2" & @CRLF)
        While _IsPressed(71)
            ; Keep increasing the sound frequency while F2 is pressed
            $beepFrequency += 50
            ConsoleWrite($beepFrequency & @CRLF)
            Beep($beepFrequency, 100)
        WEnd
        ConsoleWrite("Stopped pressing F2, resetting frequency and playing single end tone" & @CRLF)
        $beepFrequency = 300
        Beep(150, 300)
    EndIf
WEnd

Func quitter()
    Exit
EndFunc   ;==>quitter

Note that I changed the key to F2 (key 71) to make it easier to test in Scite. Also note that this script will produce sound.

Edited by SadBunny
Fixed comment

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

#include <Misc.au3>

HotKeySet("{ESC}", "ESC")
Func ESC()
    Exit
EndFunc
ToolTip("Press [ESC] button to stop this script!",0,0,"Press [Y] button!")

$i = False

While 1
    If _IsPressed(59) Then
        Beep(900.0,100)
        Do
        Until Not _IsPressed(59)
        $i = Not $i
        If $i Then
          Send("{B}")
          MouseDown("left")
        Else
          Send("{B}")
          MouseUp("left")
        EndIf
    EndIf
WEnd

You don't need to hold Y button, just press once to hold left mouse button, and when you are done, press Y button again to release left mouse button. :)

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

1 hour ago, algiuxas said:
#include <Misc.au3>

HotKeySet("{ESC}", "ESC")
Func ESC()
    Exit
EndFunc
ToolTip("Press [ESC] button to stop this script!",0,0,"Press [Y] button!")

$i = False

While 1
    If _IsPressed(59) Then
        Beep(900.0,100)
        Do
        Until Not _IsPressed(59)
        $i = Not $i
        If $i Then
          Send("{B}")
          MouseDown("left")
        Else
          Send("{B}")
          MouseUp("left")
        EndIf
    EndIf
WEnd

You don't need to hold Y button, just press once to hold left mouse button, and when you are done, press Y button again to release left mouse button. :)

it works just like i wanted! thank you so much

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

×
×
  • Create New...