Made the source tree a little nicer, added some info for Fedora users.
[umd.git] / src / umd_win32.c
blobf15c892eeabcec7f917ac7a8989fa52373e3f14c
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 *************************************************************************/
20 #include "umd.h"
21 #include "umd_private.h"
23 #if defined(_WIN32) || defined(__WIN32__)
25 #define _WIN32_WINNT 0x0500
26 #include <windows.h>
28 int UMD_Init()
30 return 0;
33 int UMD_Quit()
35 return 0;
38 int UMD_Warp(int x, int y)
40 SetCursorPos(x, y);
42 return 0;
45 int UMD_Move(int x, int y)
47 POINT point;
49 if (GetCursorPos(&point) == 0) {
50 SET_ERROR("Could not get current cursor position to move");
51 return -1;
54 SetCursorPos(point.x + x, point.y + y);
56 return 0;
59 static int get_flags(int button, int state)
61 int flags = 0;
63 switch(button) {
64 case UMD_LEFT:
65 flags = state? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
66 break;
67 case UMD_RIGHT:
68 flags = state? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
69 break;
70 case UMD_MIDDLE:
71 flags = state? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
72 break;
73 default:
74 SET_ERROR("Unrecognized mouse button in click");
75 return 0;
78 return flags;
81 int UMD_Click(int button, int state)
83 INPUT input;
84 int flags = get_flags(button, state);
86 if (flags == 0)
87 return -1;
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");
95 return -1;
98 return 0;
101 int UMD_ClickAt(int button, int state, int x, int y)
103 INPUT input;
104 int flags = get_flags(button, state);
106 if (flags == 0)
107 return -1;
109 memset(&input, 0, sizeof input);
110 input.type = INPUT_MOUSE;
111 input.mi.dwFlags = flags | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
112 input.mi.dx = x;
113 input.mi.dy = y;
115 if (SendInput(1, &input, sizeof input) != 1) {
116 SET_ERROR("Could not send click at event");
117 return -1;
120 return 0;
123 int UMD_SingleClick(int button)
125 if (UMD_Click(button, 1) < 0)
126 return -1;
128 if (UMD_Click(button, 0) < 0)
129 return -1;
131 return 0;
134 int UMD_SingleClickAt(int button, int x, int y)
136 if (UMD_ClickAt(button, 1, x, y) < 0)
137 return -1;
139 if (UMD_Click(button, 0) < 0)
140 return -1;
142 return 0;
145 #endif