dfreerdp: added keyboard and mouse input

This commit is contained in:
Marc-André Moreau 2011-08-01 12:24:29 -04:00
parent 8c03f128a7
commit ac3307f9a0
6 changed files with 183 additions and 31 deletions

View File

@ -18,6 +18,7 @@
# limitations under the License.
include_directories(../../libfreerdp-gdi)
include_directories(../../libfreerdp-kbd)
include_directories(../../libfreerdp-core)
include_directories(${DIRECTFB_INCLUDE_DIRS})
@ -29,5 +30,6 @@ add_executable(dfreerdp
target_link_libraries(dfreerdp freerdp-core)
target_link_libraries(dfreerdp freerdp-gdi)
target_link_libraries(dfreerdp freerdp-kbd)
target_link_libraries(dfreerdp freerdp-utils)
target_link_libraries(dfreerdp ${DIRECTFB_LIBRARIES})

View File

@ -17,13 +17,170 @@
* limitations under the License.
*/
#include "keyboard.h"
#include <freerdp/kbd.h>
#include "df_event.h"
uint8 keymap[256];
void df_keyboard_init()
{
memset(keymap, 0, sizeof(keymap));
/* Map DirectFB keycodes to Virtual Key Codes */
keymap[DIKI_A - DIKI_UNKNOWN] = VK_KEY_A;
keymap[DIKI_B - DIKI_UNKNOWN] = VK_KEY_B;
keymap[DIKI_C - DIKI_UNKNOWN] = VK_KEY_C;
keymap[DIKI_D - DIKI_UNKNOWN] = VK_KEY_D;
keymap[DIKI_E - DIKI_UNKNOWN] = VK_KEY_E;
keymap[DIKI_F - DIKI_UNKNOWN] = VK_KEY_F;
keymap[DIKI_G - DIKI_UNKNOWN] = VK_KEY_G;
keymap[DIKI_H - DIKI_UNKNOWN] = VK_KEY_H;
keymap[DIKI_I - DIKI_UNKNOWN] = VK_KEY_I;
keymap[DIKI_J - DIKI_UNKNOWN] = VK_KEY_J;
keymap[DIKI_K - DIKI_UNKNOWN] = VK_KEY_K;
keymap[DIKI_L - DIKI_UNKNOWN] = VK_KEY_L;
keymap[DIKI_M - DIKI_UNKNOWN] = VK_KEY_M;
keymap[DIKI_N - DIKI_UNKNOWN] = VK_KEY_N;
keymap[DIKI_O - DIKI_UNKNOWN] = VK_KEY_O;
keymap[DIKI_P - DIKI_UNKNOWN] = VK_KEY_P;
keymap[DIKI_Q - DIKI_UNKNOWN] = VK_KEY_Q;
keymap[DIKI_R - DIKI_UNKNOWN] = VK_KEY_R;
keymap[DIKI_S - DIKI_UNKNOWN] = VK_KEY_S;
keymap[DIKI_T - DIKI_UNKNOWN] = VK_KEY_T;
keymap[DIKI_U - DIKI_UNKNOWN] = VK_KEY_U;
keymap[DIKI_V - DIKI_UNKNOWN] = VK_KEY_V;
keymap[DIKI_W - DIKI_UNKNOWN] = VK_KEY_W;
keymap[DIKI_X - DIKI_UNKNOWN] = VK_KEY_X;
keymap[DIKI_Y - DIKI_UNKNOWN] = VK_KEY_Y;
keymap[DIKI_Z - DIKI_UNKNOWN] = VK_KEY_Z;
keymap[DIKI_0 - DIKI_UNKNOWN] = VK_KEY_0;
keymap[DIKI_1 - DIKI_UNKNOWN] = VK_KEY_1;
keymap[DIKI_2 - DIKI_UNKNOWN] = VK_KEY_2;
keymap[DIKI_3 - DIKI_UNKNOWN] = VK_KEY_3;
keymap[DIKI_4 - DIKI_UNKNOWN] = VK_KEY_4;
keymap[DIKI_5 - DIKI_UNKNOWN] = VK_KEY_5;
keymap[DIKI_6 - DIKI_UNKNOWN] = VK_KEY_6;
keymap[DIKI_7 - DIKI_UNKNOWN] = VK_KEY_7;
keymap[DIKI_8 - DIKI_UNKNOWN] = VK_KEY_8;
keymap[DIKI_9 - DIKI_UNKNOWN] = VK_KEY_9;
keymap[DIKI_F1 - DIKI_UNKNOWN] = VK_F1;
keymap[DIKI_F2 - DIKI_UNKNOWN] = VK_F2;
keymap[DIKI_F3 - DIKI_UNKNOWN] = VK_F3;
keymap[DIKI_F4 - DIKI_UNKNOWN] = VK_F4;
keymap[DIKI_F5 - DIKI_UNKNOWN] = VK_F5;
keymap[DIKI_F6 - DIKI_UNKNOWN] = VK_F6;
keymap[DIKI_F7 - DIKI_UNKNOWN] = VK_F7;
keymap[DIKI_F8 - DIKI_UNKNOWN] = VK_F8;
keymap[DIKI_F9 - DIKI_UNKNOWN] = VK_F9;
keymap[DIKI_F10 - DIKI_UNKNOWN] = VK_F10;
keymap[DIKI_F11 - DIKI_UNKNOWN] = VK_F11;
keymap[DIKI_F12 - DIKI_UNKNOWN] = VK_F12;
keymap[DIKI_COMMA - DIKI_UNKNOWN] = VK_OEM_COMMA;
keymap[DIKI_PERIOD - DIKI_UNKNOWN] = VK_OEM_PERIOD;
keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = VK_OEM_MINUS;
keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = VK_OEM_PLUS;
keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = VK_ESCAPE;
keymap[DIKI_LEFT - DIKI_UNKNOWN] = VK_LEFT;
keymap[DIKI_RIGHT - DIKI_UNKNOWN] = VK_RIGHT;
keymap[DIKI_UP - DIKI_UNKNOWN] = VK_UP;
keymap[DIKI_DOWN - DIKI_UNKNOWN] = VK_DOWN;
keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = VK_LCONTROL;
keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = VK_RCONTROL;
keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = VK_LSHIFT;
keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = VK_RSHIFT;
keymap[DIKI_ALT_L - DIKI_UNKNOWN] = VK_LMENU;
keymap[DIKI_ALT_R - DIKI_UNKNOWN] = VK_RMENU;
keymap[DIKI_TAB - DIKI_UNKNOWN] = VK_TAB;
keymap[DIKI_ENTER - DIKI_UNKNOWN] = VK_RETURN;
keymap[DIKI_SPACE - DIKI_UNKNOWN] = VK_SPACE;
keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = VK_BACK;
keymap[DIKI_INSERT - DIKI_UNKNOWN] = VK_INSERT;
keymap[DIKI_DELETE - DIKI_UNKNOWN] = VK_DELETE;
keymap[DIKI_HOME - DIKI_UNKNOWN] = VK_HOME;
keymap[DIKI_END - DIKI_UNKNOWN] = VK_END;
keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = VK_PRIOR;
keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = VK_NEXT;
keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = VK_CAPITAL;
keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = VK_NUMLOCK;
keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = VK_SCROLL;
keymap[DIKI_PRINT - DIKI_UNKNOWN] = VK_PRINT;
keymap[DIKI_PAUSE - DIKI_UNKNOWN] = VK_PAUSE;
keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = VK_DIVIDE;
keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = VK_MULTIPLY;
keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = VK_SUBTRACT;
keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = VK_ADD;
keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = VK_RETURN;
keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = VK_OEM_3;
keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = VK_OEM_4;
keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = VK_OEM_6;
keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = VK_OEM_5;
keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = VK_OEM_1;
keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = VK_OEM_7;
keymap[DIKI_COMMA - DIKI_UNKNOWN] = VK_OEM_COMMA;
keymap[DIKI_PERIOD - DIKI_UNKNOWN] = VK_OEM_PERIOD;
keymap[DIKI_SLASH - DIKI_UNKNOWN] = VK_OEM_2;
keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = 0;
keymap[DIKI_KP_0 - DIKI_UNKNOWN] = VK_NUMPAD0;
keymap[DIKI_KP_1 - DIKI_UNKNOWN] = VK_NUMPAD1;
keymap[DIKI_KP_2 - DIKI_UNKNOWN] = VK_NUMPAD2;
keymap[DIKI_KP_3 - DIKI_UNKNOWN] = VK_NUMPAD3;
keymap[DIKI_KP_4 - DIKI_UNKNOWN] = VK_NUMPAD4;
keymap[DIKI_KP_5 - DIKI_UNKNOWN] = VK_NUMPAD5;
keymap[DIKI_KP_6 - DIKI_UNKNOWN] = VK_NUMPAD6;
keymap[DIKI_KP_7 - DIKI_UNKNOWN] = VK_NUMPAD7;
keymap[DIKI_KP_8 - DIKI_UNKNOWN] = VK_NUMPAD8;
keymap[DIKI_KP_9 - DIKI_UNKNOWN] = VK_NUMPAD9;
keymap[DIKI_META_L - DIKI_UNKNOWN] = VK_LWIN;
keymap[DIKI_META_R - DIKI_UNKNOWN] = VK_RWIN;
keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = VK_APPS;
}
void df_send_mouse_event(rdpInput* input, boolean down, uint32 button, uint16 x, uint16 y)
{
uint16 flags;
flags = (down) ? PTR_FLAGS_DOWN : 0;
if (button == DIBI_LEFT)
flags |= PTR_FLAGS_BUTTON1;
else if (button == DIBI_RIGHT)
flags |= PTR_FLAGS_BUTTON2;
else if (button == DIBI_MIDDLE)
flags |= PTR_FLAGS_BUTTON3;
if (flags != 0)
input->MouseEvent(input, flags, x, y);
}
void df_send_keyboard_event(rdpInput* input, boolean down, uint8 keycode)
{
uint16 flags;
uint8 scancode;
boolean extended;
scancode = freerdp_kbd_get_scancode_by_virtualkey(keymap[keycode], &extended);
flags = (extended) ? KBD_FLAGS_EXTENDED : 0;
flags |= (down) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE;
input->KeyboardEvent(input, flags, scancode);
}
boolean df_event_process(freerdp* instance, DFBEvent* event)
{
GDI* gdi;
dfInfo* dfi;
int keycode;
int pointer_x;
int pointer_y;
int flags;
@ -32,8 +189,6 @@ boolean df_event_process(freerdp* instance, DFBEvent* event)
dfi = GET_DFI(instance);
gdi = GET_GDI(instance->update);
printf("process event\n");
dfi->layer->GetCursorPosition(dfi->layer, &pointer_x, &pointer_y);
if (event->clazz == DFEC_INPUT)
@ -54,31 +209,19 @@ boolean df_event_process(freerdp* instance, DFBEvent* event)
break;
case DIET_BUTTONPRESS:
flags = PTR_FLAGS_DOWN;
/* fall */
df_send_mouse_event(instance->input, True, input_event->button, pointer_x, pointer_y);
break;
case DIET_BUTTONRELEASE:
if (input_event->button == DIBI_LEFT)
flags |= PTR_FLAGS_BUTTON1;
else if (input_event->button == DIBI_RIGHT)
flags |= PTR_FLAGS_BUTTON2;
else if (input_event->button == DIBI_MIDDLE)
flags |= PTR_FLAGS_BUTTON3;
if (flags != 0)
instance->input->MouseEvent(instance->input, flags, pointer_x, pointer_y);
df_send_mouse_event(instance->input, False, input_event->button, pointer_x, pointer_y);
break;
case DIET_KEYPRESS:
keycode = input_event->key_id - DIKI_UNKNOWN;
df_send_keyboard_event(instance->input, True, input_event->key_id - DIKI_UNKNOWN);
break;
case DIET_KEYRELEASE:
keycode = input_event->key_id - DIKI_UNKNOWN;
df_send_keyboard_event(instance->input, False, input_event->key_id - DIKI_UNKNOWN);
break;
case DIET_UNKNOWN:

View File

@ -22,6 +22,7 @@
#include "dfreerdp.h"
void df_keyboard_init();
boolean df_event_process(freerdp* instance, DFBEvent* event);
#endif /* __DF_EVENT_H */

View File

@ -144,6 +144,8 @@ boolean df_post_connect(freerdp* instance)
instance->update->BeginPaint = df_begin_paint;
instance->update->EndPaint = df_end_paint;
df_keyboard_init();
return True;
}
@ -166,15 +168,11 @@ int dfreerdp_run(freerdp* instance)
instance->Connect(instance);
int count = 0;
while (1)
{
rcount = 0;
wcount = 0;
printf("loop... %d\n", count++);
if (instance->GetFileDescriptor(instance, rfds, &rcount, wfds, &wcount) != True)
{
printf("Failed to get FreeRDP file descriptor\n");
@ -196,7 +194,7 @@ int dfreerdp_run(freerdp* instance)
if (fds > max_fds)
max_fds = fds;
FD_SET(fds, &wfds_set);
FD_SET(fds, &rfds_set);
}
if (max_fds == 0)

View File

@ -23,6 +23,7 @@
#include "gdi.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <directfb.h>
#include <freerdp/freerdp.h>

View File

@ -25,11 +25,18 @@ void rdp_write_client_input_pdu_header(STREAM* s, uint16 number)
stream_write_uint16(s, 0); /* pad2Octets (2 bytes) */
}
STREAM* rdp_client_input_pdu_init(rdpRdp* rdp)
void rdp_write_input_event_header(STREAM* s, uint32 time, uint16 type)
{
stream_write_uint32(s, time); /* eventTime (4 bytes) */
stream_write_uint16(s, type); /* messageType (2 bytes) */
}
STREAM* rdp_client_input_pdu_init(rdpRdp* rdp, uint16 type)
{
STREAM* s;
s = rdp_data_pdu_init(rdp);
rdp_write_client_input_pdu_header(s, 1);
rdp_write_input_event_header(s, 0, type);
return s;
}
@ -47,7 +54,7 @@ void input_write_synchronize_event(STREAM* s, uint32 flags)
void input_send_synchronize_event(rdpInput* input, uint32 flags)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
s = rdp_client_input_pdu_init(input->rdp, INPUT_EVENT_SYNC);
input_write_synchronize_event(s, flags);
rdp_send_client_input_pdu(input->rdp, s);
}
@ -62,7 +69,7 @@ void input_write_keyboard_event(STREAM* s, uint16 flags, uint16 code)
void input_send_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
s = rdp_client_input_pdu_init(input->rdp, INPUT_EVENT_SCANCODE);
input_write_keyboard_event(s, flags, code);
rdp_send_client_input_pdu(input->rdp, s);
}
@ -77,7 +84,7 @@ void input_write_unicode_keyboard_event(STREAM* s, uint16 code)
void input_send_unicode_keyboard_event(rdpInput* input, uint16 code)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
s = rdp_client_input_pdu_init(input->rdp, INPUT_EVENT_UNICODE);
input_write_unicode_keyboard_event(s, code);
rdp_send_client_input_pdu(input->rdp, s);
}
@ -92,7 +99,7 @@ void input_write_mouse_event(STREAM* s, uint16 flags, uint16 x, uint16 y)
void input_send_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
s = rdp_client_input_pdu_init(input->rdp, INPUT_EVENT_MOUSE);
input_write_mouse_event(s, flags, x, y);
rdp_send_client_input_pdu(input->rdp, s);
}
@ -107,7 +114,7 @@ void input_write_extended_mouse_event(STREAM* s, uint16 flags, uint16 x, uint16
void input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
s = rdp_client_input_pdu_init(input->rdp, INPUT_EVENT_MOUSEX);
input_write_extended_mouse_event(s, flags, x, y);
rdp_send_client_input_pdu(input->rdp, s);
}