FreeRDP
wf_input.c
1 
20 #include <freerdp/config.h>
21 
22 #include <winpr/windows.h>
23 
24 #include "wf_input.h"
25 #include "wf_info.h"
26 
27 BOOL wf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
28 {
29  INPUT keyboard_event;
30  WINPR_UNUSED(input);
31  keyboard_event.type = INPUT_KEYBOARD;
32  keyboard_event.ki.wVk = 0;
33  keyboard_event.ki.wScan = code;
34  keyboard_event.ki.dwFlags = KEYEVENTF_SCANCODE;
35  keyboard_event.ki.dwExtraInfo = 0;
36  keyboard_event.ki.time = 0;
37 
38  if (flags & KBD_FLAGS_RELEASE)
39  keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
40 
41  if (flags & KBD_FLAGS_EXTENDED)
42  keyboard_event.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
43 
44  SendInput(1, &keyboard_event, sizeof(INPUT));
45  return TRUE;
46 }
47 
48 BOOL wf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
49 {
50  INPUT keyboard_event;
51  WINPR_UNUSED(input);
52  keyboard_event.type = INPUT_KEYBOARD;
53  keyboard_event.ki.wVk = 0;
54  keyboard_event.ki.wScan = code;
55  keyboard_event.ki.dwFlags = KEYEVENTF_UNICODE;
56  keyboard_event.ki.dwExtraInfo = 0;
57  keyboard_event.ki.time = 0;
58 
59  if (flags & KBD_FLAGS_RELEASE)
60  keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
61 
62  SendInput(1, &keyboard_event, sizeof(INPUT));
63  return TRUE;
64 }
65 
66 BOOL wf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
67 {
68  INPUT mouse_event = { 0 };
69  float width, height;
70  WINPR_UNUSED(input);
71 
72  WINPR_ASSERT(input);
73  mouse_event.type = INPUT_MOUSE;
74 
75  if (flags & PTR_FLAGS_WHEEL)
76  {
77  mouse_event.mi.dwFlags = MOUSEEVENTF_WHEEL;
78  mouse_event.mi.mouseData = flags & WheelRotationMask;
79 
80  if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
81  mouse_event.mi.mouseData *= -1;
82 
83  SendInput(1, &mouse_event, sizeof(INPUT));
84  }
85  else
86  {
87  wfInfo* wfi;
88  wfi = wf_info_get_instance();
89 
90  if (!wfi)
91  return FALSE;
92 
93  // width and height of primary screen (even in multimon setups
94  width = (float)GetSystemMetrics(SM_CXSCREEN);
95  height = (float)GetSystemMetrics(SM_CYSCREEN);
96  x += wfi->servscreen_xoffset;
97  y += wfi->servscreen_yoffset;
98  mouse_event.mi.dx = (LONG)((float)x * (65535.0f / width));
99  mouse_event.mi.dy = (LONG)((float)y * (65535.0f / height));
100  mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
101 
102  if (flags & PTR_FLAGS_MOVE)
103  {
104  mouse_event.mi.dwFlags |= MOUSEEVENTF_MOVE;
105  SendInput(1, &mouse_event, sizeof(INPUT));
106  }
107 
108  mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
109 
110  if (flags & PTR_FLAGS_BUTTON1)
111  {
112  if (flags & PTR_FLAGS_DOWN)
113  mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
114  else
115  mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
116 
117  SendInput(1, &mouse_event, sizeof(INPUT));
118  }
119  else if (flags & PTR_FLAGS_BUTTON2)
120  {
121  if (flags & PTR_FLAGS_DOWN)
122  mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;
123  else
124  mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;
125 
126  SendInput(1, &mouse_event, sizeof(INPUT));
127  }
128  else if (flags & PTR_FLAGS_BUTTON3)
129  {
130  if (flags & PTR_FLAGS_DOWN)
131  mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
132  else
133  mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
134 
135  SendInput(1, &mouse_event, sizeof(INPUT));
136  }
137  }
138 
139  return TRUE;
140 }
141 
142 BOOL wf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
143 {
144  if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2))
145  {
146  INPUT mouse_event = { 0 };
147  mouse_event.type = INPUT_MOUSE;
148 
149  if (flags & PTR_FLAGS_MOVE)
150  {
151  float width, height;
152  wfInfo* wfi;
153  wfi = wf_info_get_instance();
154 
155  if (!wfi)
156  return FALSE;
157 
158  // width and height of primary screen (even in multimon setups
159  width = (float)GetSystemMetrics(SM_CXSCREEN);
160  height = (float)GetSystemMetrics(SM_CYSCREEN);
161  x += wfi->servscreen_xoffset;
162  y += wfi->servscreen_yoffset;
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;
166  SendInput(1, &mouse_event, sizeof(INPUT));
167  }
168 
169  mouse_event.mi.dx = mouse_event.mi.dy = mouse_event.mi.dwFlags = 0;
170 
171  if (flags & PTR_XFLAGS_DOWN)
172  mouse_event.mi.dwFlags |= MOUSEEVENTF_XDOWN;
173  else
174  mouse_event.mi.dwFlags |= MOUSEEVENTF_XUP;
175 
176  if (flags & PTR_XFLAGS_BUTTON1)
177  mouse_event.mi.mouseData = XBUTTON1;
178  else if (flags & PTR_XFLAGS_BUTTON2)
179  mouse_event.mi.mouseData = XBUTTON2;
180 
181  SendInput(1, &mouse_event, sizeof(INPUT));
182  }
183  else
184  {
185  wf_peer_mouse_event(input, flags, x, y);
186  }
187 
188  return TRUE;
189 }
190 
191 BOOL wf_peer_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT8 code)
192 {
193  WINPR_UNUSED(input);
194  WINPR_UNUSED(flags);
195  WINPR_UNUSED(code);
196  return TRUE;
197 }
198 
199 BOOL wf_peer_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
200 {
201  WINPR_UNUSED(input);
202  WINPR_UNUSED(flags);
203  WINPR_UNUSED(code);
204  return TRUE;
205 }
206 
207 BOOL wf_peer_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
208 {
209  WINPR_UNUSED(input);
210  WINPR_UNUSED(flags);
211  WINPR_UNUSED(x);
212  WINPR_UNUSED(y);
213  return TRUE;
214 }
215 
216 BOOL wf_peer_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
217 {
218  WINPR_UNUSED(input);
219  WINPR_UNUSED(flags);
220  WINPR_UNUSED(x);
221  WINPR_UNUSED(y);
222  return TRUE;
223 }