X-Git-Url: https://git.sesse.net/?p=rdpsrv;a=blobdiff_plain;f=rdpsrv.c;h=91989872cf530955bd5cd274a21f858e9d09818a;hp=c838fc7a60c711d7f7ec8434a9b9755ad8040feb;hb=132e47e292eea211b9ab0ba2f835cb7f41197ada;hpb=dbccf42e4424093cfc0f970d1fcfaad9ae60c954 diff --git a/rdpsrv.c b/rdpsrv.c index c838fc7..9198987 100644 --- a/rdpsrv.c +++ b/rdpsrv.c @@ -8,6 +8,7 @@ #include #include "rdesktop.h" +#include "scancodes.h" const int tcp_port_rdp = 3389; int create_server_socket(); @@ -58,6 +59,30 @@ int create_server_socket() listen(server_sock, 20); return server_sock; } + +int map_scancode_to_vnc_key(int scancode) +{ + switch (scancode) + { + case SCANCODE_CHAR_1 ... SCANCODE_CHAR_9: + return scancode + '1' - SCANCODE_CHAR_1; + case SCANCODE_CHAR_0: + return '0'; + case SCANCODE_CHAR_BACKSPACE: + return 0xff08; + case SCANCODE_CHAR_TAB: + return 0xff09; + case SCANCODE_CHAR_Q ... SCANCODE_CHAR_P: + return "QWERTYUIOP"[scancode - SCANCODE_CHAR_Q]; + case SCANCODE_CHAR_A ... SCANCODE_CHAR_L: + return "ASDFGHJKL"[scancode - SCANCODE_CHAR_A]; + case SCANCODE_CHAR_Z ... SCANCODE_CHAR_M: + return "ZXCVBNM"[scancode - SCANCODE_CHAR_Z]; + default: + printf("Unknown scancode %x, ignoring\n", scancode); + return -1; + } +} void handle_input_pdu(STREAM s, int vnc_sock) { @@ -67,6 +92,7 @@ void handle_input_pdu(STREAM s, int vnc_sock) int i; char buf[256]; static int mouse1_down = 0, mouse2_down = 0; + int vnc_key; in_uint16_le(s, num_events); // number of events in_uint8s(s, 2); // pad @@ -86,7 +112,24 @@ void handle_input_pdu(STREAM s, int vnc_sock) printf("- Type: Virtual key (ignored)\n"); break; case RDP_INPUT_SCANCODE: - printf("- Type: Scancode (ignored)\n"); + printf("- Type: Scancode\n"); + printf("- Device flags: %x\n", device_flags); + printf("- Key: %x\n", param1); + + vnc_key = map_scancode_to_vnc_key(param1); + + if (vnc_key != -1) { + buf[0] = 4; // message type + buf[1] = (device_flags & KBD_FLAG_DOWN) ? 1 : 0; // down flag + buf[2] = 0; // padding + buf[3] = 0; + buf[4] = vnc_key >> 24; // keysym + buf[5] = (vnc_key >> 16) & 0xff; + buf[6] = (vnc_key >> 8) & 0xff; + buf[7] = vnc_key & 0xff; + write(vnc_sock, buf, 8); + } + break; case RDP_INPUT_MOUSE: printf("- Type: Mouse\n"); @@ -97,6 +140,8 @@ void handle_input_pdu(STREAM s, int vnc_sock) mouse1_down = (device_flags & MOUSE_FLAG_DOWN) ? 0x01 : 0; if (device_flags & MOUSE_FLAG_BUTTON2) mouse2_down = (device_flags & MOUSE_FLAG_DOWN) ? 0x02 : 0; + + printf("button mask = %x\n", mouse1_down | mouse2_down); buf[0] = 5; // message type buf[1] = mouse1_down | mouse2_down; // button mask @@ -335,9 +380,18 @@ int serve_client() error("short read on vnc_sock\n"); handle_vnc_fbupdate(vnc_sock); break; - case 2: + case 2: // bell printf("\n"); break; + case 3: + printf("New text in clipboard, ignoring\n"); + if (read(vnc_sock, buf, 3) != 3) + error("short read on vnc_sock\n"); + if (read(vnc_sock, buf, 4) != 4) + error("short read on vnc_sock\n"); + if (read(vnc_sock, buf, (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) != 4) + error("short read on vnc_sock\n"); + default: printf("Unknown VNC server message %x\n", buf[0]); exit(1);