Commit 759c17c8 authored by abmyii's avatar abmyii
Browse files

Get keyboard input working

parent a3a50df1
......@@ -5,8 +5,8 @@ all: $(BINS)
VNCLIBS=-lvncserver
MIRCFLAGS=-std=c++11 -Wall -fpermissive -I/usr/include/mirclient -I/usr/include/mircommon -I/usr/include/mircore
MIRLIBS=-lboost_program_options -lpthread -lmirclient -lmirprotobuf -lEGL -lxcb-glx -lGLESv2 -lmirserver -lmircore
MIRCFLAGS=-std=c++11 -Wall -fpermissive -I/usr/include/mirclient -I/usr/include/mircommon -I/usr/include/mircore -I/usr/include/libevdev-1.0
MIRLIBS=-lboost_program_options -lpthread -lmirclient -lmirprotobuf -lEGL -lxcb-glx -lGLESv2 -lmirserver -lmircore -levdev
dummyvncserver: dummyvncserver.c
$(CC) dummyvncserver.c -o dummyvncserver $(VNCLIBS)
......
......@@ -46,6 +46,11 @@
#include <rfb/rfb.h>
#include <rfb/keysym.h>
#include <stdio.h>
#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
namespace po = boost::program_options;
namespace
......@@ -62,6 +67,9 @@ volatile sig_atomic_t running = 1;
*/
thread_local int dummy_tls[2];
struct libevdev *dev;
struct libevdev_uinput *uidev;
void shutdown(int)
{
running = 0;
......@@ -279,15 +287,175 @@ struct EGLSetup
GLenum read_pixel_format;
};
// https://github.com/hanzelpeter/dispmanx_vnc/blob/master/main.c
static int keysym2scancode(rfbKeySym key)
{
//printf("keysym: %04X\n", key);
int scancode = 0;
int code = (int) key;
if (code>='0' && code<='9') {
scancode = (code & 0xF) - 1;
if (scancode<0) scancode += 10;
scancode += KEY_1;
} else if (code>=0xFF50 && code<=0xFF58) {
static const uint16_t map[] =
{ KEY_HOME, KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN,
KEY_PAGEUP, KEY_PAGEDOWN, KEY_END, 0 };
scancode = map[code & 0xF];
} else if (code>=0xFFE1 && code<=0xFFEE) {
static const uint16_t map[] =
{ KEY_LEFTSHIFT, KEY_LEFTSHIFT,
KEY_LEFTCTRL, KEY_LEFTCTRL,
KEY_LEFTSHIFT, KEY_LEFTSHIFT,
0,0,
KEY_LEFTALT, KEY_RIGHTALT,
0, 0, 0, 0 };
scancode = map[code & 0xF];
} else if ((code>='A' && code<='Z') || (code>='a' && code<='z')) {
static const uint16_t map[] = {
KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T,
KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z };
scancode = map[(code & 0x5F) - 'A'];
} else {
switch (code) {
case XK_space: scancode = KEY_SPACE; break;
case XK_exclam: scancode = KEY_1; break;
case XK_at: scancode = KEY_2; break;
case XK_numbersign: scancode = KEY_3; break;
case XK_dollar: scancode = KEY_4; break;
case XK_percent: scancode = KEY_5; break;
case XK_asciicircum: scancode = KEY_6; break;
case XK_ampersand: scancode = KEY_7; break;
case XK_asterisk: scancode = KEY_8; break;
case XK_parenleft: scancode = KEY_9; break;
case XK_parenright: scancode = KEY_0; break;
case XK_minus: scancode = KEY_MINUS; break;
case XK_underscore: scancode = KEY_MINUS; break;
case XK_equal: scancode = KEY_EQUAL; break;
case XK_plus: scancode = KEY_EQUAL; break;
case XK_BackSpace: scancode = KEY_BACKSPACE; break;
case XK_Tab: scancode = KEY_TAB; break;
case XK_braceleft: scancode = KEY_LEFTBRACE; break;
case XK_braceright: scancode = KEY_RIGHTBRACE; break;
case XK_bracketleft: scancode = KEY_LEFTBRACE; break;
case XK_bracketright: scancode = KEY_RIGHTBRACE; break;
case XK_Return: scancode = KEY_ENTER; break;
case XK_semicolon: scancode = KEY_SEMICOLON; break;
case XK_colon: scancode = KEY_SEMICOLON; break;
case XK_apostrophe: scancode = KEY_APOSTROPHE; break;
case XK_quotedbl: scancode = KEY_APOSTROPHE; break;
case XK_grave: scancode = KEY_GRAVE; break;
case XK_asciitilde: scancode = KEY_GRAVE; break;
case XK_backslash: scancode = KEY_BACKSLASH; break;
case XK_bar: scancode = KEY_BACKSLASH; break;
case XK_comma: scancode = KEY_COMMA; break;
case XK_less: scancode = KEY_COMMA; break;
case XK_period: scancode = KEY_DOT; break;
case XK_greater: scancode = KEY_DOT; break;
case XK_slash: scancode = KEY_SLASH; break;
case XK_question: scancode = KEY_SLASH; break;
case XK_Caps_Lock: scancode = KEY_CAPSLOCK; break;
case XK_F1: scancode = KEY_F1; break;
case XK_F2: scancode = KEY_F2; break;
case XK_F3: scancode = KEY_F3; break;
case XK_F4: scancode = KEY_F4; break;
case XK_F5: scancode = KEY_F5; break;
case XK_F6: scancode = KEY_F6; break;
case XK_F7: scancode = KEY_F7; break;
case XK_F8: scancode = KEY_F8; break;
case XK_F9: scancode = KEY_F9; break;
case XK_F10: scancode = KEY_F10; break;
case XK_Num_Lock: scancode = KEY_NUMLOCK; break;
case XK_Scroll_Lock: scancode = KEY_SCROLLLOCK; break;
case XK_Page_Down: scancode = KEY_PAGEDOWN; break;
case XK_Insert: scancode = KEY_INSERT; break;
case XK_Delete: scancode = KEY_DELETE; break;
case XK_Page_Up: scancode = KEY_PAGEUP; break;
case XK_Escape: scancode = KEY_ESC; break;
case XK_KP_Divide: scancode = KEY_KPSLASH; break;
case XK_KP_Multiply: scancode = KEY_KPASTERISK; break;
case XK_KP_Add: scancode = KEY_KPPLUS; break;
case XK_KP_Subtract: scancode = KEY_KPMINUS; break;
case XK_KP_Enter: scancode = KEY_KPENTER; break;
case XK_KP_Decimal:
case XK_KP_Delete:
scancode = KEY_KPDOT; break;
case XK_KP_0:
case XK_KP_Insert:
scancode = KEY_KP0; break;
case XK_KP_1:
case XK_KP_End:
scancode = KEY_KP1; break;
case XK_KP_2:
case XK_KP_Down:
scancode = KEY_KP2; break;
case XK_KP_3:
case XK_KP_Page_Down:
scancode = KEY_KP3; break;
case XK_KP_4:
case XK_KP_Left:
scancode = KEY_KP4; break;
case XK_KP_5:
scancode = KEY_KP5; break;
case XK_KP_6:
case XK_KP_Right:
scancode = KEY_KP6; break;
case XK_KP_7:
case XK_KP_Home:
scancode = KEY_KP7; break;
case XK_KP_8:
case XK_KP_Up:
scancode = KEY_KP8; break;
case XK_KP_9:
case XK_KP_Page_Up:
scancode = KEY_KP9; break;
}
}
return scancode;
}
// vnc key event function, escape to quit
static void dokey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
{
if(down) {
if(key==XK_Escape)
if(key==XK_Escape) {
/* close down server, disconnecting clients */
rfbShutdownServer(cl->screen,TRUE);
running = 0;
}
printf("%d Down\n", key);
printf("%d Down\n", KEY_A);
}
libevdev_uinput_write_event(uidev, EV_KEY, keysym2scancode(key), down);
libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
}
void do_screencast(EGLSetup const& egl_setup,
......@@ -358,6 +526,19 @@ try
bool query_params_only = false;
int capture_interval = 1;
// Fake keyboard device
int err;
dev = libevdev_new();
libevdev_set_name(dev, "fake keyboard device");
libevdev_enable_event_type(dev, EV_KEY);
for (int i = 0; i < KEY_MAX; i++)
libevdev_enable_event_code(dev, EV_KEY, i, NULL);
err = libevdev_uinput_create_from_device(dev,
LIBEVDEV_UINPUT_OPEN_MANAGED,
&uidev);
//avoid unused warning/error
dummy_tls[0] = 0;
......@@ -492,6 +673,8 @@ try
do_screencast(egl_setup, screencast_size, number_of_captures, capture_fps, file_stream);
}
libevdev_uinput_destroy(uidev);
return EXIT_SUCCESS;
}
catch(std::exception const& e)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment