forked from leeyiw/vnc2rdp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.c
153 lines (136 loc) · 3.68 KB
/
input.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* vnc2rdp: proxy for RDP client connect to VNC server
*
* Copyright 2014 Yiwei Li <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "input.h"
#include "log.h"
#include "vnc.h"
static int
v2r_input_process_keyboard_event(v2r_rdp_t *r, v2r_packet_t *p)
{
uint16_t keyboard_flags, key_code;
V2R_PACKET_READ_UINT16_LE(p, keyboard_flags);
V2R_PACKET_READ_UINT16_LE(p, key_code);
V2R_PACKET_SEEK_UINT16(p);
v2r_log_debug("keyboard_flags: 0x%x, key_code: 0x%x", keyboard_flags,
key_code);
// TODO XKeycodeToKeysym
//if (v2r_vnc_send_key_event(r->session->vnc, 1, 0x0051) == -1) {
// goto fail;
//}
//if (v2r_vnc_send_key_event(r->session->vnc, 0, 0x0051) == -1) {
// goto fail;
//}
return 0;
fail:
return -1;
}
static int
v2r_input_process_mouse_event(v2r_rdp_t *r, v2r_packet_t *p)
{
uint8_t button_mask = 0;
static uint8_t button1_clicked, button2_clicked, button3_clicked;
uint16_t pointer_flags;
static uint16_t x_pos, y_pos;
V2R_PACKET_READ_UINT16_LE(p, pointer_flags);
if (pointer_flags & PTRFLAGS_MOVE) {
V2R_PACKET_READ_UINT16_LE(p, x_pos);
V2R_PACKET_READ_UINT16_LE(p, y_pos);
} else {
V2R_PACKET_SEEK(p, 4);
}
if (pointer_flags & PTRFLAGS_WHEEL) {
if (pointer_flags & PTRFLAGS_WHEEL_NEGATIVE) {
button_mask = RFB_POINTER_WHEEL_DOWNWARDS;
} else {
button_mask = RFB_POINTER_WHEEL_UPWARDS;
}
if (v2r_vnc_send_pointer_event(r->session->vnc, button_mask, x_pos,
y_pos) == -1) {
goto fail;
}
if (v2r_vnc_send_pointer_event(r->session->vnc, 0, x_pos,
y_pos) == -1) {
goto fail;
}
} else {
if (pointer_flags & PTRFLAGS_BUTTON1) {
button1_clicked = pointer_flags & PTRFLAGS_DOWN ? 1 : 0;
} else if (pointer_flags & PTRFLAGS_BUTTON2) {
button2_clicked = pointer_flags & PTRFLAGS_DOWN ? 1 : 0;
} else if (pointer_flags & PTRFLAGS_BUTTON3) {
button3_clicked = pointer_flags & PTRFLAGS_DOWN ? 1 : 0;
}
if (button1_clicked) {
button_mask |= RFB_POINTER_BUTTON_LEFT;
}
if (button2_clicked) {
button_mask |= RFB_POINTER_BUTTON_RIGHT;
}
if (button3_clicked) {
button_mask |= RFB_POINTER_BUTTON_MIDDLE;
}
if (v2r_vnc_send_pointer_event(r->session->vnc, button_mask, x_pos,
y_pos) == -1) {
goto fail;
}
}
return 0;
fail:
return -1;
}
int
v2r_input_process(v2r_rdp_t *r, v2r_packet_t *p)
{
uint16_t i, num_events, message_type;
uint32_t event_time;
V2R_PACKET_READ_UINT16_LE(p, num_events);
V2R_PACKET_SEEK_UINT16(p);
for (i = 0; i < num_events; i++) {
V2R_PACKET_READ_UINT32_LE(p, event_time);
V2R_PACKET_READ_UINT16_LE(p, message_type);
switch (message_type) {
case INPUT_EVENT_SYNC:
V2R_PACKET_SEEK(p, 6);
break;
case INPUT_EVENT_UNUSED:
V2R_PACKET_SEEK(p, 6);
break;
case INPUT_EVENT_SCANCODE:
if (v2r_input_process_keyboard_event(r, p) == -1) {
goto fail;
}
break;
case INPUT_EVENT_UNICODE:
V2R_PACKET_SEEK(p, 6);
break;
case INPUT_EVENT_MOUSE:
if (v2r_input_process_mouse_event(r, p) == -1) {
goto fail;
}
break;
case INPUT_EVENT_MOUSEX:
V2R_PACKET_SEEK(p, 6);
break;
default:
v2r_log_warn("unknown input event message type 0x%x", message_type);
break;
}
}
return 0;
fail:
return -1;
}