cgv
Loading...
Searching...
No Matches
mouse_ctrl.cxx
1#include "mouse_ctrl.h"
2
3#ifdef WIN32
4#define WIN32_LEAN_AND_MEAN
5#include <windows.h>
6#else
7#include <iostream>
8#endif
9
10namespace cgv {
11 namespace os {
12
13#ifdef WIN32
14void set_mouse_cursor(int x, int y)
15{
16 SetCursorPos(x, y);
17}
18bool get_mouse_cursor(int& x, int& y)
19{
20 POINT p;
21 if (GetCursorPos(&p) == TRUE) {
22 x = p.x;
23 y = p.y;
24 return true;
25 }
26 return false;
27}
28
29void send_mouse_button_event(int button, bool press_not_release)
30{
31 static const DWORD mouse_button_flag[6] = {
32 MOUSEEVENTF_LEFTUP, MOUSEEVENTF_MIDDLEUP, MOUSEEVENTF_RIGHTUP,
33 MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_RIGHTDOWN
34 };
35 INPUT inputs[1] = { 0 };
36 inputs[0].type = INPUT_MOUSE;
37 inputs[0].mi.dwFlags = mouse_button_flag[button + press_not_release?3:0];
38 SendInput(1, inputs, sizeof(INPUT));
39}
40void send_mouse_wheel_event(float dy)
41{
42 INPUT inputs[1] = { 0 };
43 inputs[0].type = INPUT_MOUSE;
44 inputs[0].mi.dwFlags = MOUSEEVENTF_WHEEL;
45 inputs[0].mi.mouseData = DWORD(120 * dy);
46 SendInput(1, inputs, sizeof(INPUT));
47}
48#else
50void set_mouse_cursor(int x, int y)
51{
52 std::cerr << "cgv::os::set_mouse_cursor(x,y) not implemented on this platform" << std::endl;
53}
54bool get_mouse_cursor(int& x, int& y)
55{
56 std::cerr << "cgv::os::get_mouse_cursor(x, y) not implemented on this platform" << std::endl;
57 return false;
58}
59void send_mouse_button_event(int button, bool press_not_release)
60{
61 std::cerr << "cgv::os::send_mouse_button_event(button,press_not_release) not implemented on this platform" << std::endl;
62}
63void send_mouse_wheel_event(float dy)
64{
65 std::cerr << "cgv::os::send_mouse_wheel_event(dy) not implemented on this platform" << std::endl;
66}
67#endif
68
69 }
70}
the cgv namespace
Definition print.h:11