Jump to content

Proactive Mouse Event Trapping


Guest Sundown
 Share

Recommended Posts

Here I go again with a guess:

#include <misc.au3>

While 1
    If _IsPressed('01') Then; 01 is left-click
        While _IsPressed('01') = 1
            Send("w")
            Sleep(10)
        WEnd
    EndIf
    If _IsPressed('02') Then; 02 is right-click
        While _IsPressed('02') = 1
            Local $Pos = MouseGetPos()
            MouseClick("left", $Pos[0], $Pos[1], 1, 1)
            Sleep(10)
        WEnd
    EndIf
    If _IsPressed('1b') = 1 Then Exit;1b is ESC
WEnd

I appreciate your help here. Let me demonstrate why that script doesn't do exactly what I was aiming for. I assume you are using Scite to code these examples. Open the script in Scite and put the insertion point at the end of the last line, i.e. after "WEnd". Now run the script, i.e. press F5. Now move the mouse-cursor up into the text of the script, i.e. between the "0" and "2" of "_IsPressed('02')". Now hold the left-mouse-button down.

Instead of typing "w" at the end of "WEnd" where you had originally placed the insertion point, it instead types "w" between the "02". Obviously this is because the left-click is "leaking through". If you were to move the mouse up and down while holding the left-button down, it would highlight the surrounding text, then replace it with "w".

How can you map the "left-click" so that it does not "leak through?"

Link to comment
Share on other sites

  • Moderators

You keep saying leaking through... You are not going to stop a click from it's initial output.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Might this work?

GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "mouseclick", WinGetHandle ("title"))

Where you specify the title of the window you're attempting to control.

Hmm, doesn't look like it. Just tried - being nonGUI, I don't think it's going to work out. But the idea's still there.

Thanks for your ideas too. I tried this GUI approach, but had two problems:

1. The 100% transparent GUI still sort of "fuzzies" the overall screen.

2. The script doesn't capture all clicks, i.e. if I click quickly, sometimes they get missed.

Since the GUI is full-screen, it captures and intercepts all mouse-clicks. After detecting the left-click anywhere on the full-screen, could I then pass that left-click to a particular coordinate on the screen? I was possibly thinking I could save the mouse position, "hide" the transparent GUI, MouseClick, then "show" the transparent GUI? This seems clunky.

All suggestions are welcome, thanks.

#include <GUIConstants.au3>

AutoItSetOption ( "MouseClickDelay", 10)
HotKeySet("^p", "DetectLeftClick")
HotKeySet("{ESC}", "ExitOut")

Global $activate

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

$activate = 0

DetectLeftClick()

Func DetectLeftClick()
    $activate = NOT $activate
    While $activate
       $msg = GUIGetMsg()
       If $msg = $GUI_EVENT_PRIMARYDOWN Then
         Do
           ;$msg = GUIGetMsg()
           ;MouseClick("left",800,600,1,0)
            MsgBox(0,"clicked left button","click detected", 1)
        ;Send("clicked")
        ;Until $msg = $GUI_EVENT_PRIMARYUP
         Until 1
     EndIf
    ;Sleep(0)
    Wend
EndFunc

Func ExitOut()
    Exit
EndFunc
Link to comment
Share on other sites

Okay, I hear you. You're all saying it is impossible. That is a very significant endpoint for me. I have been searching the forums for this definitive statement for quite some time. There are about a dozen various posts talking about this idea, but each time people suggest _IsPressed, and then do not answer further questions about the "leak-through" effect.

In fact, the same thing happened with the original post of this thread that I hijacked! I wonder how he was able to re-map a "right-click" into a "double-left-click"?

I have been accomplishing this re-mapping of right/left/middle mouse-clicks by using AutoHotKey instead of AutoIt, but I like AutoIt's functions and syntax a whole lot better. I was hoping there would be some solution that I was overlooking.

Thanks very much!

(p.s. if there are any other ideas, I'd love to hear them) :lmao:

Link to comment
Share on other sites

...How can you map the "left-click" so that it does not "leak through?"

To quote ezzetabi:

...something like hotkeyset but with less limitations! And it should not 'steal' the key from other apps.

http://www.autoitscript.com/forum/index.ph...536entry40536

There might be something in that thread about trapping - but I doubt it. HotKeySet does keep the key from the app and IsPressed was made not to do that.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

To quote ezzetabi:

http://www.autoitscript.com/forum/index.ph...536entry40536

There might be something in that thread about trapping - but I doubt it. HotKeySet does keep the key from the app and IsPressed was made not to do that.

I went through that thread a long time ago, and I don't remember that it addressed the issue. However, I did think about what seems to be the key-line in the _IsPressed script:

$aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)

I thought perhaps there is some other DllCall or GetAsyncKeyState function or alternative that would get the key state without leaking the actual key itself. I even looked it up on MSDN web page or something, but I don't know anything about these DllCalls or anything, so I didn't know what to look for.

Link to comment
Share on other sites

Something keeps HotKeys that are set from getting thru - I just don't know what.

I would not say that it cannot be done, but I have not seen a lot of requests for such a feature. Is it in the idea lab forum - or do you want to post it there?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Moderators

I would not say that it cannot be done

Agreed!

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I've been looking for DllCall possibilities, and I have no clue what it'd be called. I can't seem to find anything that would do what we want. Someone more familiar with the source (a developer would be nice) needs to come help us out. We could all use some info on how HotKeySet works, and how we can do the same thing with mouse button clicks.

Link to comment
Share on other sites

Something keeps HotKeys that are set from getting thru - I just don't know what.

I would not say that it cannot be done, but I have not seen a lot of requests for such a feature. Is it in the idea lab forum - or do you want to post it there?

It never occurred to me to ever read the Idea Lab forum! Interesting stuff in there. Yes, a request to use "extra buttons" as HotKeySet is in there. I assume it would be applicable for "left-right-middle buttons" also.

http://www.autoitscript.com/forum/index.ph...topic=13718&hl=

I think it would be wonderful to be able to trap the button presses (i.e. single-click, double-click, CTRL-click, Shift-click, etc.), evaluate the clicks without sending the clicks, then perform (or NOT perform) the desired function. Since it is seems clear that a combination of HotKeySet and _IsPressed would be able to accomplish this task, I hope it is just an easily changed option.

Thanks everyone,

Link to comment
Share on other sites

  • 6 months later...

Ok, well I've been working on this for a while, and I (like the rest of you) did not find a way to block the "leakage" before the autoit function took place. Although for his example I did come up with a solution. This would be different for each mouse key assigning script you write, depending on the conditions. For his example he wanted to click the back button whenever he right clicks. Well instead of trying to get around the context menu popping up... why not just work with it? Here is what I have:

#include <misc.au3>
AdlibEnable("Mouse", 5)
HotKeySet("{End}", "Shutoff")

While 1
    Sleep(100)
WEnd

Func Mouse()
    If _IsPressed(02) Then
        Sleep(100)
        Send("B")
    EndIf
EndFunc

Func Shutoff()
    Exit
EndFunc

Now I totaly understand that you are trying to completely stop the "leaked" default mouse action from coming through, and if they enable mouse buttons as hotkeys, this would be a whole lot easier for us. But for now we might as well just work with what we have.

Edited by dandymcgee

- Dan [Website]

Link to comment
Share on other sites

  • 4 weeks later...

While reading this it occurred to me that what you want is mouse gestures? Opera have them and I think I have seen a plugin to get it in firefox?

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