Core Function MouseHook

From Sputnik Wiki
Jump to: navigation, search
MouseHook( <name>, <command>, <param var> )

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

param var

Optional; A variable to pass inside the mousehook this variable will become $Param this is most useful for attaching a class to the mousehook so you can access its variables, functions natively.

Return Value

Success: Returns true.

Failure: Returns @PTRZero.

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 pressing P key will remove it
// Set a new MouseHook called MyHook pressing P key will remove it
Global $a = MouseHook("MyHook", 'myMouseHook($arg, $key);');
 
HotKeySet("p", "removeIt();");
Function removeIt()
{
	MouseHook("MyHook");
}
 
while(true)
{
	DoEvents();
}
 
Function myMouseHook($arg, $key)
{
	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;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox