Jump to content

_IsPressed Mouse AutoFire?


Recommended Posts

Here is an interesting question. I'm using the IsPressed function to detect when my left mousebutton is pressed down. When I press it down, I want AutoIt to send "repeated" leftclicks... then when I let up on the left mousebutton, I want AutoIt to stop sending leftclicks.

The interesting problem though is AutoIt can't sense that I am holding down the left mousebutton AND send multiple left mouseclicks at the same time... or at least I think that's what the problem is. Here is my code.

Global $activate
AutoItSetOption ( "MouseClickDelay", 10)

$letter = "^p"
HotKeySet($letter, "ToggleActivate")
Func ToggleActivate()
    $activate = NOT $activate
    While $activate
         If _IsPressed('01') = 1 Then MouseClick("left",800,600,1,0)
         Sleep(40);this compensates for the mouseclick delay being at 0
    Wend
EndFunc

Func _IsPressed($hexKey)
; $hexKey must be the value of one of the keys.
; _IsPressed will return 0 if the key is not pressed, 1 if it is.
 Local $aR
 $hexKey = '0x' & $hexKey
 $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
 If Not @error And BitAND($aR[0],0x8000) = 0x8000 Then Return 1
 Return 0
EndFunc

While 1
    Sleep(100);infinite loop
WEnd

Does anyone have a solution? Oh, and if you're confused about my problem, then think of it this way... I'm trying to build a rapid-fire script (i.e., hold down a button and the thing auto-fires until I release the button).

Edited by ozone
Link to comment
Share on other sites

The _IsPressed is also detecting mouse action by the MouseClick() function.

Here's a simple flowchart:

1. User: Left click and hold.

2. IsPressed: Detects left mouse down.

3. MouseClick: Sends left mouse down, then up.

4. IsPressed: Detects Step 3's mouse up, thinks the user released left click.

5. User: Releases left click whenever, it doesn't matter cus the script is ignoring it.

Link to comment
Share on other sites

Instead of using _IsPressed() I used the GUI event message. Because it only works for GUI's it creates a window that fills the whole screen and then sets the transparency to zero like its not even there. I think it should work but... I cant even get the hot key work. The theory and coding is correct for everything I think, except for the hot key. Any if you can get the hot key it should work :(.

#include <GUIConstants.au3>

AutoItSetOption ( "MouseClickDelay", 10)
HotKeySet("^p", "ToggleActivate")
Global $activate

$gui = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
WinSetTrans ($gui, "", 0)
GUISetState()

While 1
    Sleep(100)
WEnd

Func ToggleActivate()
    $activate = NOT $activate
    While $activate
       $msg = GUIGetMsg()
       If $msg = $GUI_EVENT_PRIMARYDOWN Then
         Do
            $msg = GUIGetMsg()
            MouseClick("left",800,600,1,0)
         Until $msg = $GUI_EVENT_PRIMARYUP
       EndIf
    Wend
EndFunc

qq

Link to comment
Share on other sites

  • 5 years later...

Instead of using _IsPressed() I used the GUI event message. Because it only works for GUI's it creates a window that fills the whole screen and then sets the transparency to zero like its not even there. I think it should work but... I cant even get the hot key work. The theory and coding is correct for everything I think, except for the hot key. Any if you can get the hot key it should work :huh2:.

#include <GUIConstants.au3>

AutoItSetOption ( "MouseClickDelay", 10)
HotKeySet("^p", "ToggleActivate")
Global $activate

$gui = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
WinSetTrans ($gui, "", 0)
GUISetState()

While 1
    Sleep(100)
WEnd

Func ToggleActivate()
    $activate = NOT $activate
    While $activate
       $msg = GUIGetMsg()
       If $msg = $GUI_EVENT_PRIMARYDOWN Then
         Do
            $msg = GUIGetMsg()
            MouseClick("left",800,600,1,0)
         Until $msg = $GUI_EVENT_PRIMARYUP
       EndIf
    Wend
EndFunc

It doesn't work at all. Can someone fix this code, I don't know what's the problem. And I don't get this hotkey part, no one needs it.
Link to comment
Share on other sites

  • Developers

It doesn't work at all. Can someone fix this code, I don't know what's the problem. And I don't get this hotkey part, no one needs it.

So let me get this strait: you resurrect a thread from 2005 and now WANT someone to fix this code for you?

What is stopping you for have a go at it first?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Follow the code line by line. Look at just 1 line at a time and see what it does. If you don't know what a command does, look it up in the help file as it explains it very simply.

This should be very easy to follow.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Follow the code line by line. Look at just 1 line at a time and see what it does. If you don't know what a command does, look it up in the help file as it explains it very simply.

This should be very easy to follow.

Even the person WHO MADE the code couldn't get it run, for me it's impossible.
Link to comment
Share on other sites

Probably because they didn't make their gui clickthrough

I can't remember how to do it offhand, but there are examples in the forum.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

I'm trying to build a rapid-fire script (i.e., hold down a button and the thing auto-fires until I release the button).

Doesnt that mean its for a game, or can atleast be used for that?

I hate rapid-fire mods/scripts/programs

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

  • Developers

Folks, this is a 6 years old thread ... lets close this discussion as I am pretty sure the OP will not respond as he didn't check in since 2009.

*click*

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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