Core Function MouseHook
(Created page with "<pre> MouseHook( <name>, <command> ) </pre> === Description === Places a global system wide MouseHook with callback to a function or command. === Parameters === ==== name ===...") |
(→Example) |
||
Line 37: | Line 37: | ||
=== Example === | === Example === | ||
− | <syntaxhighlight lang="sputnik"> | + | <syntaxhighlight lang="sputnik">// Set a new MouseHook called MyHook |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | // Set a new MouseHook called MyHook | + | |
MouseHook("MyHook", "myMouseHook();"); | MouseHook("MyHook", "myMouseHook();"); | ||
Line 62: | Line 50: | ||
if($nCode >= 0) | if($nCode >= 0) | ||
{ | { | ||
− | my | + | my List( $X, $Y, $vkCode, $scanCode, $flags, $time, $dwExtraInfo ) = $key; |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
switch ($wParam) | switch ($wParam) | ||
{ | { | ||
Line 89: | Line 71: | ||
{ | { | ||
print("Right Button UP "); | print("Right Button UP "); | ||
+ | } | ||
+ | break; | ||
+ | case 0x0207: // WM_MBUTTONDOWN | ||
+ | { | ||
+ | print("Middle Button DOWN "); | ||
+ | } | ||
+ | break; | ||
+ | case 0x0208: // WM_MBUTTONUP | ||
+ | { | ||
+ | print("Middle Button UP "); | ||
} | } | ||
break; | break; |
Revision as of 00:45, 2 May 2012
MouseHook( <name>, <command> )
Contents |
Description
Places a global system wide MouseHook with callback to a function or command.
Parameters
name
Unique name for the new MouseHook (So it can be removed later!)
If this is the only param used it will try delete a previously made hook by this name.
If a hook already exists with this name it will be replaced with the new code (assuming second param is in use)
command
Optional; A command or function to call etc when the MouseHook event triggers on a mouse move, click etc.
This is similar to Eval().
Return Value
Success: Returns 1.
Failure: Returns 0.
Remarks
A MouseHook will cause your program to crash if you dont add DoEvents() in your code see below example.
If only the NAME param is used and NOT the command it will add that name to the delete list and the hook of that name (if any exist) will be removed at the earliest opportunity.
Example
// Set a new MouseHook called MyHook MouseHook("MyHook", "myMouseHook();"); while(true) { DoEvents(); } Function myMouseHook() { my List( $Name, $nCode, $wParam, $lParam ) = $arg; if($nCode >= 0) { my List( $X, $Y, $vkCode, $scanCode, $flags, $time, $dwExtraInfo ) = $key; switch ($wParam) { case 0x0201: // WM_LBUTTONDOWN { print("Left Button DOWN "); } break; case 0x0202: // WM_LBUTTONUP { print("Left Button UP "); } break; case 0x0204: // WM_RBUTTONDOWN { print("Right Button DOWN "); } break; case 0x0205: // WM_RBUTTONUP { print("Right Button UP "); } break; case 0x0207: // WM_MBUTTONDOWN { print("Middle Button DOWN "); } break; case 0x0208: // WM_MBUTTONUP { print("Middle Button UP "); } break; case 0x0200: // WM_MOUSEMOVE { print("Move "); } break; case 0x020A: // WM_MOUSEWHEEL { print("Wheel "); } break; } print("X $X, Y: $Y\n"); } // Must return false or else the hook will be removed // To remove the hook simply return TRUE somewhere // Or you can set the hook without a second param example: // MouseHook("MyHook"); // This will remove the hook return false; }