2
* FreeRDP: A Remote Desktop Protocol Implementation
3
* FreeRDP Windows Server
5
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
* you may not use this file except in compliance with the License.
9
* You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
24
#include <winpr/windows.h>
29
void wf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
33
keyboard_event.type = INPUT_KEYBOARD;
34
keyboard_event.ki.wVk = 0;
35
keyboard_event.ki.wScan = code;
36
keyboard_event.ki.dwFlags = KEYEVENTF_SCANCODE;
37
keyboard_event.ki.dwExtraInfo = 0;
38
keyboard_event.ki.time = 0;
40
if (flags & KBD_FLAGS_RELEASE)
41
keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
43
if (flags & KBD_FLAGS_EXTENDED)
44
keyboard_event.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
46
SendInput(1, &keyboard_event, sizeof(INPUT));
49
void wf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
53
keyboard_event.type = INPUT_KEYBOARD;
54
keyboard_event.ki.wVk = 0;
55
keyboard_event.ki.wScan = code;
56
keyboard_event.ki.dwFlags = KEYEVENTF_UNICODE;
57
keyboard_event.ki.dwExtraInfo = 0;
58
keyboard_event.ki.time = 0;
60
if (flags & KBD_FLAGS_RELEASE)
61
keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
63
SendInput(1, &keyboard_event, sizeof(INPUT));
66
void wf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
71
ZeroMemory(&mouse_event, sizeof(INPUT));
72
mouse_event.type = INPUT_MOUSE;
74
if (flags & PTR_FLAGS_WHEEL)
76
mouse_event.mi.dwFlags = MOUSEEVENTF_WHEEL;
77
mouse_event.mi.mouseData = flags & WheelRotationMask;
79
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
80
mouse_event.mi.mouseData *= -1;
82
SendInput(1, &mouse_event, sizeof(INPUT));
88
wfi = wf_info_get_instance();
90
//width and height of primary screen (even in multimon setups
91
width = (float) GetSystemMetrics(SM_CXSCREEN);
92
height = (float) GetSystemMetrics(SM_CYSCREEN);
94
x += wfi->servscreen_xoffset;
95
y += wfi->servscreen_yoffset;
97
mouse_event.mi.dx = (LONG) ((float) x * (65535.0f / width));
98
mouse_event.mi.dy = (LONG) ((float) y * (65535.0f / height));
99
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
101
if (flags & PTR_FLAGS_MOVE)
103
mouse_event.mi.dwFlags |= MOUSEEVENTF_MOVE;
104
SendInput(1, &mouse_event, sizeof(INPUT));
107
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
109
if (flags & PTR_FLAGS_BUTTON1)
111
if (flags & PTR_FLAGS_DOWN)
112
mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
114
mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
116
SendInput(1, &mouse_event, sizeof(INPUT));
118
else if (flags & PTR_FLAGS_BUTTON2)
120
if (flags & PTR_FLAGS_DOWN)
121
mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;
123
mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;
125
SendInput(1, &mouse_event, sizeof(INPUT));
127
else if (flags & PTR_FLAGS_BUTTON3)
129
if (flags & PTR_FLAGS_DOWN)
130
mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
132
mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
134
SendInput(1, &mouse_event, sizeof(INPUT));
139
void wf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
141
if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2))
144
ZeroMemory(&mouse_event, sizeof(INPUT));
146
mouse_event.type = INPUT_MOUSE;
148
if (flags & PTR_FLAGS_MOVE)
153
wfi = wf_info_get_instance();
154
//width and height of primary screen (even in multimon setups
155
width = (float) GetSystemMetrics(SM_CXSCREEN);
156
height = (float) GetSystemMetrics(SM_CYSCREEN);
158
x += wfi->servscreen_xoffset;
159
y += wfi->servscreen_yoffset;
161
//mouse_event.mi.dx = x * (0xFFFF / width);
162
//mouse_event.mi.dy = y * (0xFFFF / height);
163
mouse_event.mi.dx = (LONG) ((float) x * (65535.0f / width));
164
mouse_event.mi.dy = (LONG) ((float) y * (65535.0f / height));
165
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
167
SendInput(1, &mouse_event, sizeof(INPUT));
170
mouse_event.mi.dx = mouse_event.mi.dy = mouse_event.mi.dwFlags = 0;
172
if (flags & PTR_XFLAGS_DOWN)
173
mouse_event.mi.dwFlags |= MOUSEEVENTF_XDOWN;
175
mouse_event.mi.dwFlags |= MOUSEEVENTF_XUP;
177
if (flags & PTR_XFLAGS_BUTTON1)
178
mouse_event.mi.mouseData = XBUTTON1;
179
else if (flags & PTR_XFLAGS_BUTTON2)
180
mouse_event.mi.mouseData = XBUTTON2;
182
SendInput(1, &mouse_event, sizeof(INPUT));
186
wf_peer_mouse_event(input, flags, x, y);
191
void wf_peer_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
195
void wf_peer_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
199
void wf_peer_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
203
void wf_peer_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)