Convert keycode to RdevKey

This commit is contained in:
Asura 2022-08-26 18:29:46 -07:00
parent b38c3299d8
commit ee19a03ecc
8 changed files with 147 additions and 76 deletions

75
Cargo.lock generated
View File

@ -627,21 +627,6 @@ dependencies = [
"cc",
]
[[package]]
name = "cocoa"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "667fdc068627a2816b9ff831201dd9864249d6ee8d190b9532357f1fc0f61ea7"
dependencies = [
"bitflags",
"block",
"core-foundation 0.9.3",
"core-graphics 0.21.0",
"foreign-types",
"libc",
"objc",
]
[[package]]
name = "cocoa"
version = "0.24.0"
@ -759,18 +744,6 @@ dependencies = [
"libc",
]
[[package]]
name = "core-graphics"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978"
dependencies = [
"bitflags",
"core-foundation 0.9.3",
"foreign-types",
"libc",
]
[[package]]
name = "core-graphics"
version = "0.22.3"
@ -1283,6 +1256,26 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "enum-map"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5a56d54c8dd9b3ad34752ed197a4eb2a6601bc010808eb097a04a58ae4c43e1"
dependencies = [
"enum-map-derive",
]
[[package]]
name = "enum-map-derive"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9045e2676cd5af83c3b167d917b0a5c90a4d8e266e2683d6631b235c457fc27"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "enum_dispatch"
version = "0.3.8"
@ -3741,15 +3734,17 @@ dependencies = [
[[package]]
name = "rdev"
version = "0.5.0"
source = "git+https://github.com/open-trade/rdev#fbbefd0b5d87095a7349965aec9ecd33de7035ac"
version = "0.5.0-2"
source = "git+https://github.com/asur4s/rdev#895c8fb1a6106714793e8877d35d2b7a1c57ce9c"
dependencies = [
"cocoa 0.22.0",
"core-foundation 0.7.0",
"core-foundation-sys 0.7.0",
"core-graphics 0.19.2",
"cocoa",
"core-foundation 0.9.3",
"core-foundation-sys 0.8.3",
"core-graphics 0.22.3",
"enum-map",
"lazy_static",
"libc",
"widestring 1.0.2",
"winapi 0.3.9",
"x11",
]
@ -3967,7 +3962,7 @@ dependencies = [
"cfg-if 1.0.0",
"clap 3.1.18",
"clipboard",
"cocoa 0.24.0",
"cocoa",
"core-foundation 0.9.3",
"core-graphics 0.22.3",
"cpal",
@ -4939,7 +4934,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76863575f7842ed64fda361f417a787efa82811b4617267709066969cd4ccf3b"
dependencies = [
"cocoa 0.24.0",
"cocoa",
"core-graphics 0.22.3",
"gtk",
"libappindicator",
@ -5357,6 +5352,12 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c"
[[package]]
name = "widestring"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
[[package]]
name = "winapi"
version = "0.2.8"
@ -5430,7 +5431,7 @@ checksum = "0c643e10139d127d30d6d753398c8a6f0a43532e8370f6c9d29ebbff29b984ab"
dependencies = [
"bitflags",
"err-derive",
"widestring",
"widestring 0.4.3",
"winapi 0.3.9",
]
@ -5557,7 +5558,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b43cc931d58b99461188607efd7acb2a093e65fc621f54cad78517a6063e73a"
dependencies = [
"bitflags",
"cocoa 0.24.0",
"cocoa",
"core-foundation 0.9.3",
"core-graphics 0.22.3",
"core-video-sys",

View File

@ -74,7 +74,7 @@ sciter-rs = { git = "https://github.com/open-trade/rust-sciter", branch = "dyn"
sys-locale = "0.2"
enigo = { path = "libs/enigo", features = [ "with_serde" ] }
clipboard = { path = "libs/clipboard" }
rdev = { git = "https://github.com/open-trade/rdev" }
rdev = { git = "https://github.com/asur4s/rdev" }
ctrlc = "3.2"
arboard = "2.0"
#minreq = { version = "2.4", features = ["punycode", "https-native"] }

View File

@ -234,6 +234,89 @@ class _RemotePageState extends State<RemotePage>
buildBody(context, ffiModel))));
}
KeyEventResult handleRawKeyEvent(FocusNode data, RawKeyEvent e) {
String? keyboardMode = Platform.environment['KEYBOARD_MODE'];
keyboardMode ??= 'legacy';
if (keyboardMode == 'map') {
mapKeyboardMode(e);
} else if (keyboardMode == 'translate') {
legacyKeyboardMode(e);
} else {
legacyKeyboardMode(e);
}
return KeyEventResult.handled;
}
void mapKeyboardMode(RawKeyEvent e) {
int scanCode;
int keyCode;
bool down;
if (e.data is RawKeyEventDataMacOs) {
RawKeyEventDataMacOs newData = e.data as RawKeyEventDataMacOs;
scanCode = newData.keyCode;
keyCode = newData.keyCode;
} else if (e.data is RawKeyEventDataWindows) {
RawKeyEventDataWindows newData = e.data as RawKeyEventDataWindows;
scanCode = newData.scanCode;
keyCode = newData.keyCode;
} else if (e.data is RawKeyEventDataLinux) {
RawKeyEventDataLinux newData = e.data as RawKeyEventDataLinux;
scanCode = newData.scanCode;
keyCode = newData.keyCode;
debugPrint(newData.unicodeScalarValues.toString());
} else {
scanCode = -1;
keyCode = -1;
}
if (e is RawKeyDownEvent){
down = true;
}else{
down = false;
}
_ffi.inputRawKey(keyCode, scanCode, down);
}
void legacyKeyboardMode(RawKeyEvent e) {
final key = e.logicalKey;
if (e is RawKeyDownEvent) {
if (e.repeat) {
sendRawKey(e, press: true);
} else {
if (e.isAltPressed && !_ffi.alt) {
_ffi.alt = true;
} else if (e.isControlPressed && !_ffi.ctrl) {
_ffi.ctrl = true;
} else if (e.isShiftPressed && !_ffi.shift) {
_ffi.shift = true;
} else if (e.isMetaPressed && !_ffi.command) {
_ffi.command = true;
}
sendRawKey(e, down: true);
}
}
if (e is RawKeyUpEvent) {
if (key == LogicalKeyboardKey.altLeft ||
key == LogicalKeyboardKey.altRight) {
_ffi.alt = false;
} else if (key == LogicalKeyboardKey.controlLeft ||
key == LogicalKeyboardKey.controlRight) {
_ffi.ctrl = false;
} else if (key == LogicalKeyboardKey.shiftRight ||
key == LogicalKeyboardKey.shiftLeft) {
_ffi.shift = false;
} else if (key == LogicalKeyboardKey.metaLeft ||
key == LogicalKeyboardKey.metaRight) {
_ffi.command = false;
}
sendRawKey(e);
}
}
Widget getRawPointerAndKeyBody(Widget child) {
return Consumer<FfiModel>(
builder: (context, FfiModel, _child) => MouseRegion(
@ -249,42 +332,7 @@ class _RemotePageState extends State<RemotePage>
onFocusChange: (bool v) {
_imageFocused = v;
},
onKey: (data, e) {
final key = e.logicalKey;
if (e is RawKeyDownEvent) {
if (e.repeat) {
sendRawKey(e, press: true);
} else {
if (e.isAltPressed && !_ffi.alt) {
_ffi.alt = true;
} else if (e.isControlPressed && !_ffi.ctrl) {
_ffi.ctrl = true;
} else if (e.isShiftPressed && !_ffi.shift) {
_ffi.shift = true;
} else if (e.isMetaPressed && !_ffi.command) {
_ffi.command = true;
}
sendRawKey(e, down: true);
}
}
if (e is RawKeyUpEvent) {
if (key == LogicalKeyboardKey.altLeft ||
key == LogicalKeyboardKey.altRight) {
_ffi.alt = false;
} else if (key == LogicalKeyboardKey.controlLeft ||
key == LogicalKeyboardKey.controlRight) {
_ffi.ctrl = false;
} else if (key == LogicalKeyboardKey.shiftRight ||
key == LogicalKeyboardKey.shiftLeft) {
_ffi.shift = false;
} else if (key == LogicalKeyboardKey.metaLeft ||
key == LogicalKeyboardKey.metaRight) {
_ffi.command = false;
}
sendRawKey(e);
}
return KeyEventResult.handled;
},
onKey: handleRawKeyEvent,
child: child))));
}

View File

@ -980,6 +980,12 @@ class FFI {
msg: json.encode(modify({'type': type, 'buttons': button.value})));
}
// Raw Key
void inputRawKey(int keyCode, int scanCode, bool down){
debugPrint(scanCode.toString());
bind.sessionInputRawKey(id: id, keycode: keyCode, scancode: scanCode, down: down);
}
/// Send key stroke event.
/// [down] indicates the key's state(down or up).
/// [press] indicates a click event(down and up).

View File

@ -1649,7 +1649,7 @@ pub enum Data {
}
/// Keycode for key events.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum Key {
ControlKey(ControlKey),
Chr(u32),

View File

@ -373,6 +373,16 @@ impl Session {
}
}
pub fn input_raw_key(&self, keycode: i32, scancode: i32, down: bool){
use rdev::{EventType::*, Key as RdevKey, *};
if scancode < 0 || keycode < 0{
return;
}
let key = rdev::key_from_scancode(scancode.try_into().unwrap()) as RdevKey;
log::info!("{:?}", key);
}
/// Input a string of text.
/// String is parsed into individual key presses.
///

View File

@ -208,6 +208,12 @@ pub fn session_switch_display(id: String, value: i32) {
}
}
pub fn session_input_raw_key(id: String, keycode: i32, scancode:i32, down: bool){
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.input_raw_key(keycode, scancode, down);
}
}
pub fn session_input_key(
id: String,
name: String,

View File

@ -1,5 +1,5 @@
use crate::ipc::{self, new_listener, Connection, Data};
#[cfg(windows)]
#[cfg(target_os = "linux")]
use crate::ipc::{start_pa};
#[cfg(windows)]
use crate::ipc::start_clipboard_file;