Add modifier keys support on Linux. Fix #3
This commit is contained in:
parent
3114c7b7ff
commit
0a651cc187
|
@ -180,14 +180,13 @@ void event_callback(XPointer p, XRecordInterceptData *hook)
|
|||
|
||||
switch (event_type) {
|
||||
case KeyRelease:
|
||||
//printf ("%d %d KeyPress: \t%s\t%s\n", key_code, res, XKeysymToString(XkbKeycodeToKeysym(ctrl_disp, key_code, 0, 0)), buffer.data());
|
||||
if (res > 0) { // Send only printable chars, todo: change
|
||||
keypress_callback(interceptor_instance, buffer.data(), buffer.size());
|
||||
//printf ("%d %d %s\n", key_code, res, buffer.data());
|
||||
if (res > 0 && key_code != 22) { // Printable character, but not backspace
|
||||
keypress_callback(interceptor_instance, buffer.data(), buffer.size(), 0, key_code);
|
||||
}else{ // Modifier key
|
||||
keypress_callback(interceptor_instance, NULL, 0, 1, key_code);
|
||||
}
|
||||
break;
|
||||
// case KeyPress:
|
||||
// printf ("%d %d KeyPress: \t%s\t%s\t%d\n", keycode, res, XKeysymToString(XkbKeycodeToKeysym(ctrl_disp, keycode, 0, 0)), buff, buff[0]);
|
||||
// break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ extern "C" void cleanup();
|
|||
* Called when a new keypress is made, the first argument is an char array,
|
||||
* while the second is the size of the array.
|
||||
*/
|
||||
typedef void (*KeypressCallback)(void * self, char *buffer, int32_t len);
|
||||
typedef void (*KeypressCallback)(void * self, const char *buffer, int32_t len, int32_t is_modifier, int32_t key_code);
|
||||
|
||||
extern KeypressCallback keypress_callback;
|
||||
extern void * interceptor_instance;
|
||||
|
|
|
@ -54,10 +54,10 @@ impl super::KeyboardSender for LinuxKeyboardSender {
|
|||
|
||||
// Native bridge code
|
||||
|
||||
extern fn keypress_callback(_self: *mut LinuxKeyboardInterceptor, raw_buffer: *const u8, len: i32) {
|
||||
extern fn keypress_callback(_self: *mut LinuxKeyboardInterceptor, raw_buffer: *const u8, len: i32,
|
||||
is_modifier: i32, key_code: i32) {
|
||||
unsafe {
|
||||
//if is_modifier == 0 { // Char event
|
||||
if true { // Char event
|
||||
if is_modifier == 0 { // Char event
|
||||
// Convert the received buffer to a character
|
||||
let buffer = std::slice::from_raw_parts(raw_buffer, len as usize);
|
||||
let r = String::from_utf8_lossy(buffer).chars().nth(0);
|
||||
|
@ -67,13 +67,12 @@ extern fn keypress_callback(_self: *mut LinuxKeyboardInterceptor, raw_buffer: *c
|
|||
(*_self).sender.send(KeyEvent::Char(c)).unwrap();
|
||||
}
|
||||
}else{ // Modifier event
|
||||
let key_code = 3;
|
||||
let modifier: Option<KeyModifier> = match key_code {
|
||||
0x37 => Some(META),
|
||||
0x38 => Some(SHIFT),
|
||||
0x3A => Some(ALT),
|
||||
0x3B => Some(CTRL),
|
||||
0x33 => Some(BACKSPACE),
|
||||
133 => Some(META),
|
||||
50 => Some(SHIFT),
|
||||
64 => Some(ALT),
|
||||
37 => Some(CTRL),
|
||||
22 => Some(BACKSPACE),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
@ -87,7 +86,9 @@ extern fn keypress_callback(_self: *mut LinuxKeyboardInterceptor, raw_buffer: *c
|
|||
#[allow(improper_ctypes)]
|
||||
#[link(name="linuxbridge", kind="static")]
|
||||
extern {
|
||||
fn register_keypress_callback(s: *const LinuxKeyboardInterceptor, cb: extern fn(_self: *mut LinuxKeyboardInterceptor, *const u8, i32));
|
||||
fn register_keypress_callback(s: *const LinuxKeyboardInterceptor,
|
||||
cb: extern fn(_self: *mut LinuxKeyboardInterceptor, *const u8,
|
||||
i32, i32, i32));
|
||||
fn initialize();
|
||||
fn eventloop();
|
||||
fn cleanup();
|
||||
|
|
Loading…
Reference in New Issue
Block a user