Jump to content

How do I start/stop a function when a button is pressed/released?


LNGS
 Share

Recommended Posts

Hi! This will be my first post on here, and Autoit is the first language I learn, so please be patient!

I have spent quite some time searching and trying to understand what I ask for in the topic title without much progress.

I can only start the function with HotKeySet, but I want it to run when I press the button and stop when I release it.

I tried to use GetKeyState, but found no way of stopping the function alone.

Then I tried to understand _IsPressed and use it with an If else section, but I kept getting errors all the time..

So.. I signed up here hoping maybe I could get some help with this.

 

Here is my code:

While 1
Sleep(50)
WEnd

HotKeySet ( "del" [, "Fire"] )

Dim $pos[2]
Func Fire()
   MouseDown ( "left" )
   $pos = MouseGetPos()
   MouseMove($pos[0]-1,$pos[1]+15,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]-1,$pos[1]+16,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]-1,$pos[1]+15,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]-1,$pos[1]+20,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]-1,$pos[1]+33,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]+4,$pos[1]+44,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]+10,$pos[1]+25,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]+20,$pos[1]+19,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]+25,$pos[1]+15,1)
      sleep(90)
   $pos = MouseGetPos()
   MouseMove($pos[0]+40,$pos[1]+15,1)
   MouseUp ( "left" )
EndFunc
Link to comment
Share on other sites

  • Moderators

Look at Interrupting a Running Function on the Wiki:

https://www.autoitscript.com/wiki/Interrupting_a_running_function

 

Edit: What application are you trying to manipulate? There may be better ways than doing a bunch of MouseMoves. especially if you're interrupting the function in the middle.

Edited by JLogan3o13

"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

Look at Interrupting a Running Function on the Wiki:

https://www.autoitscript.com/wiki/Interrupting_a_running_function

 

Edit: What application are you trying to manipulate? There may be better ways than doing a bunch of MouseMoves. especially if you're interrupting the function in the middle.

 

Maybe I'm stupid but I have already tried to understand what is explained in that link, and it looks so messy to me and I tried cutting some parts out that I understood and use it in my own code but I keep getting different errors..

In my head it would be so damn easy to do if I there were just a command to stop a function without pausing or stopping the entire script. For example, GetKeyState "del" returning false could stop function "fire"... Easy!

......

This is a no-recoil script for fps games, something I choose to do because it is rewarding in its own way.

I don't enjoy cheating in games but for some reason I got this idea and it has been a lot of fun figuring out how to do it so far.

I guess it is my way of staying motivated in learning this language, I hope you understand even tho my English is not very good, if so maybe we can skip the moral lession? :)

Thanks for responding!

Link to comment
Share on other sites

  • Moderators

Unfortunately, LNGS, you missed the Forum Rules on your way in, specifically the part where Game Automation and Interaction is prohibited on this forum. Morals aside, it is against the rules so we do not assist in such scripts (not to mention it being lame). Please read through the rules, and you'll see why you won't get any further assistance on this topic. Hope to see you soon with a legitimate topic, though.

"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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...