1 /*************************************************************************
2 Copyright (C) 2009 Matthew Thompson <chameleonator@gmail.com>
4 This file is part of libumd.
6 libumd is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 libumd is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libumd. If not, see <http://www.gnu.org/licenses/>.
18 *************************************************************************/
21 #include "umd_private.h"
23 #if defined(_WIN32) || defined(__WIN32__)
25 #define _WIN32_WINNT 0x0500
38 int UMD_Warp(int x
, int y
)
45 int UMD_Move(int x
, int y
)
49 if (GetCursorPos(&point
) == 0) {
50 SET_ERROR("Could not get current cursor position to move");
54 SetCursorPos(point
.x
+ x
, point
.y
+ y
);
59 static int get_flags(int button
, int state
)
65 flags
= state
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_LEFTUP
;
68 flags
= state
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_RIGHTUP
;
71 flags
= state
? MOUSEEVENTF_MIDDLEDOWN
: MOUSEEVENTF_MIDDLEUP
;
74 SET_ERROR("Unrecognized mouse button in click");
81 int UMD_Click(int button
, int state
)
84 int flags
= get_flags(button
, state
);
89 memset(&input
, 0, sizeof input
);
90 input
.type
= INPUT_MOUSE
;
91 input
.mi
.dwFlags
= flags
;
93 if (SendInput(1, &input
, sizeof input
) != 1) {
94 SET_ERROR("Could not send click event");
101 int UMD_ClickAt(int button
, int state
, int x
, int y
)
104 int flags
= get_flags(button
, state
);
109 memset(&input
, 0, sizeof input
);
110 input
.type
= INPUT_MOUSE
;
111 input
.mi
.dwFlags
= flags
| MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
;
115 if (SendInput(1, &input
, sizeof input
) != 1) {
116 SET_ERROR("Could not send click at event");
123 int UMD_SingleClick(int button
)
125 if (UMD_Click(button
, 1) < 0)
128 if (UMD_Click(button
, 0) < 0)
134 int UMD_SingleClickAt(int button
, int x
, int y
)
136 if (UMD_ClickAt(button
, 1, x
, y
) < 0)
139 if (UMD_Click(button
, 0) < 0)