Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hook and eat
#1
Hi gintaras, Hi all

i try to adapt the mouse hook you gave in the AltMouseTriggers function.

As I play with it, i often now have freezed laptop, so I ask before screwing all.

I want to "eat" RButtonDown in firefox for example, and don't act on any other program.
But handling firefox "eating" mouse button should be done in an external function DoAction.

Is this code correct to do so? Is it mandatory to use ret to achieve that?

Code:
Copy      Help
if(getopt(nargs)=0)
    int+ g_mhook=SetWindowsHookEx(WH_MOUSE_LL &AltMouseTriggers _hinst 0)
    opt waitmsg 1
    AddTrayIcon "mouse.ico" "My mouse triggers" ;;remove this line if tray icon is not needed
    wait -1 -V g_mhook
    ret

if(nCode<0) goto g1
if(m.flags&LLMHF_INJECTED) goto g1 ;;not user-generated

sel wParam
     case [WM_LBUTTONDOWN]
     _s.getwinclass(win(mouse))
         if(StrCompare(_s "Mozilla*WindowClass))
                _i=DoAction("Firefox") ;;!!!!!<----action done in DoAction function, must eat mouse click.!!!!!
               if(_i=1) ret _i; else goto g1
     else goto g1



g1
ret CallNextHookEx(g_mhook nCode wParam m)
#2
To eat the event, the hook code must return 1. No other ways exist.
The hook code must be as fast as possible. If need to run longer, start other macro with mac. Of course it cannot eat, because only the hook code can do it - return 1.
#3
sel wParam
case [WM_LBUTTONDOWN]
_s.getwinclass(win(mouse))
if(StrCompare(_s "Mozilla*WindowClass))
DoAction("Firefox") ;;!!!!!<----action done in DoAction function, must eat mouse click.!!!!!
ret 1
else goto g1

can this work? If click in firefox, eat other way pass
#4
If DoAction is fast, both codes are correct.
#5
I don't know exactly, depends on action of course.

What to put in DoAction to launch a independant process, then return at once in hook function
to do ret 1 or goto g1.

a. Another function? DoFirefoxActionFunction
b. Another Macro? mac "DoFirefoxActionMacro"
c. Function launched by mac DoFirefoxActionFunction?
d. something else?
#6
DoAction can start other macro with mac, or do anything, but it must return as soon as possible.
#7
From previous discussion, i thought that a function can act on its own once launched, so that the function where it started from
can be terminated. I was thinking about launching another independent thread by function in DoAction.

As understood that macro launched would make DoAction stalled until the macro is over.

Am I wrong?

So the picture

- - - - - - >Hook function
| |
| |
- - - - - - - -DoAction -----> independent function (thread) DoActionFirefox

Correct?
#8
If a function is called like DoAction("a"), caller waits until it returns.
If a function is started like mac "DoAction" "" "a", caller does not wait.
#9
Ok, so the fastest chain would then be:

Hook function --> if firefox is underneath mouse when click ---> hook function calls mac "DoAction" "" "Firefox" --> In doAction, calls mac DoActionFirefox "" "Firefox" --> DoAction is immediatly
able to return in hook function to get ret1 éeat" the mouse click --> in hook function ret 1

it seems the quickest way to do things.

Comment??
#10
It starts 2 new threads. Usually need 1, but I don't know your code.
#11
Ok, seems to run fine here.

Thanks


Forum Jump:


Users browsing this thread: 1 Guest(s)