Saturday, March 17th, 2012, 460 days ago
Why mapping hand gestures to system mouse pointer controls?
Hand gesture recognition, including hand gestures and movements, is becoming increasingly attractive. Many people are currently working on it to achieve natural interaction. One important step between hand gesture recognition and natural-interaction applications is to map detected hand gestures to system mouse pointer control. In one of previous articles here.
In this article an simple example is provided to demonstrate how to map detected hand gestures’ movements to system mouse pointer position using c#.
Because my current work is focusing on c#, this example is written in c#. For other programme languages, such as c++ and c, the principle is similar, the detail functions may be different though.
Below is the source codes of this example, comments are given to explain what does each line mean.
//load system dll file user32.dll
//define a static function as entrance of user32.dll
static extern int SetCursorPos(int x, int y);
//the main function
static void Main(string args)
//a 1000 loop
for (int i = 0; i < 1000; i++)
//key part: set mouse position to specific position
//press any key to continue to next position
Step further – more operations with mouse pointer control
There are other functions specified to take over system mouse pointer control.
static extern void mouse_event(MouseEventFlag flags, int x, int y, unit data, UIntPrt extraInfo);
enum MouseEventFlag : Unit
Move = 0×0001,
LeftDown = 0×0002,
LeftUp = 0×0004,
RightDown = 0×0008,
RightUp = 0×0010,
MiddleDown = 0×0020,
MiddleUp = 0×0040,
XDown = 0×0080,
XUp = 0×0100,
Wheel = 0×0800,
VirtualDesk = 0×4000,
Absolute = 0×8000
It is not working to use
to trigger a mouse left button click at [10,10].
To realise that, there needs two steps.
1) moving pointer to right position [10,10].
2) triggering a left button click event, by using
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero).
POSTS MAY BE OF INTEREST