simulate scancode for translate mode
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
94d7339457
commit
d8dbf72ad2
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -4840,7 +4840,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rdev"
|
name = "rdev"
|
||||||
version = "0.5.0-2"
|
version = "0.5.0-2"
|
||||||
source = "git+https://github.com/fufesou/rdev#aeea78dec3e731dd616da09668bbbd835a773d6c"
|
source = "git+https://github.com/fufesou/rdev#b866494215329f3e8e4863c3c5fb98a10297610c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"core-foundation 0.9.3",
|
"core-foundation 0.9.3",
|
||||||
|
@ -10,7 +10,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use flutter_rust_bridge::{StreamSink, SyncReturn};
|
use flutter_rust_bridge::{StreamSink, SyncReturn};
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
allow_err,
|
|
||||||
config::{self, LocalConfig, PeerConfig, PeerInfoSerde, ONLINE},
|
config::{self, LocalConfig, PeerConfig, PeerInfoSerde, ONLINE},
|
||||||
fs, log,
|
fs, log,
|
||||||
message_proto::KeyboardMode,
|
message_proto::KeyboardMode,
|
||||||
@ -1396,10 +1395,10 @@ pub fn send_url_scheme(_url: String) {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub fn plugin_event(id: String, event: Vec<u8>) {
|
pub fn plugin_event(_id: String, _event: Vec<u8>) {
|
||||||
#[cfg(feature = "plugin_framework")]
|
#[cfg(feature = "plugin_framework")]
|
||||||
{
|
{
|
||||||
allow_err!(crate::plugin::handle_ui_event(&id, &event));
|
allow_err!(crate::plugin::handle_ui_event(&_id, &_event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,19 +15,9 @@ use std::{
|
|||||||
thread,
|
thread,
|
||||||
time::{self, Duration, Instant},
|
time::{self, Duration, Instant},
|
||||||
};
|
};
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
use winapi::um::winuser::{
|
|
||||||
ActivateKeyboardLayout, GetForegroundWindow, GetKeyboardLayout, GetWindowThreadProcessId,
|
|
||||||
VkKeyScanW,
|
|
||||||
};
|
|
||||||
|
|
||||||
const INVALID_CURSOR_POS: i32 = i32::MIN;
|
const INVALID_CURSOR_POS: i32 = i32::MIN;
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
lazy_static::lazy_static! {
|
|
||||||
static ref LAST_HKL: Arc<Mutex<u32>> = Arc::new(Mutex::new(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct StateCursor {
|
struct StateCursor {
|
||||||
hcursor: u64,
|
hcursor: u64,
|
||||||
@ -1244,45 +1234,7 @@ fn translate_process_code(code: u32, down: bool) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn check_update_input_layout() {
|
|
||||||
unsafe {
|
|
||||||
let foreground_thread_id =
|
|
||||||
GetWindowThreadProcessId(GetForegroundWindow(), std::ptr::null_mut());
|
|
||||||
let layout = GetKeyboardLayout(foreground_thread_id);
|
|
||||||
let layout_u32 = layout as u32;
|
|
||||||
let mut last_layout_lock = LAST_HKL.lock().unwrap();
|
|
||||||
if *last_layout_lock == 0 || *last_layout_lock != layout_u32 {
|
|
||||||
let res = ActivateKeyboardLayout(layout, 0);
|
|
||||||
if res == layout {
|
|
||||||
*last_layout_lock = layout_u32;
|
|
||||||
} else {
|
|
||||||
log::error!("Failed to call ActivateKeyboardLayout, {}", layout_u32);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn translate_keyboard_mode(evt: &KeyEvent) {
|
fn translate_keyboard_mode(evt: &KeyEvent) {
|
||||||
// --server could not detect the input layout change.
|
|
||||||
// This is a temporary workaround.
|
|
||||||
//
|
|
||||||
// There may be a better way to detect and handle the input layout change.
|
|
||||||
// while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
|
|
||||||
// {
|
|
||||||
// ...
|
|
||||||
// if (msg.message == WM_INPUTLANGCHANGE)
|
|
||||||
// {
|
|
||||||
// // handle WM_INPUTLANGCHANGE message here
|
|
||||||
// check_update_input_layout();
|
|
||||||
// }
|
|
||||||
// TranslateMessage(&msg);
|
|
||||||
// DispatchMessage(&msg);
|
|
||||||
// ...
|
|
||||||
// }
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
check_update_input_layout();
|
|
||||||
|
|
||||||
match &evt.union {
|
match &evt.union {
|
||||||
Some(key_event::Union::Seq(seq)) => {
|
Some(key_event::Union::Seq(seq)) => {
|
||||||
// Fr -> US
|
// Fr -> US
|
||||||
@ -1305,7 +1257,7 @@ fn translate_keyboard_mode(evt: &KeyEvent) {
|
|||||||
}
|
}
|
||||||
for chr in seq.chars() {
|
for chr in seq.chars() {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
rdev::simulate_char(chr).ok();
|
rdev::simulate_char(chr, true).ok();
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
en.key_click(Key::Layout(chr));
|
en.key_click(Key::Layout(chr));
|
||||||
}
|
}
|
||||||
@ -1334,27 +1286,7 @@ fn translate_keyboard_mode(evt: &KeyEvent) {
|
|||||||
fn simulate_win2win_hotkey(code: u32, down: bool) {
|
fn simulate_win2win_hotkey(code: u32, down: bool) {
|
||||||
let unicode: u16 = (code & 0x0000FFFF) as u16;
|
let unicode: u16 = (code & 0x0000FFFF) as u16;
|
||||||
if down {
|
if down {
|
||||||
// Try convert unicode to virtual keycode first.
|
if rdev::simulate_key_unicode(unicode, false).is_ok() {
|
||||||
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-vkkeyscanw
|
|
||||||
let res = unsafe { VkKeyScanW(unicode) };
|
|
||||||
if res as u16 != 0xFFFF {
|
|
||||||
let vk = res & 0x00FF;
|
|
||||||
let flag = res >> 8;
|
|
||||||
let modifiers = [rdev::Key::ShiftLeft, rdev::Key::ControlLeft, rdev::Key::Alt];
|
|
||||||
let mod_len = modifiers.len();
|
|
||||||
for pos in 0..mod_len {
|
|
||||||
if flag & (0x0001 << pos) != 0 {
|
|
||||||
allow_err!(rdev::simulate(&EventType::KeyPress(modifiers[pos])));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
allow_err!(rdev::simulate_code(Some(vk as _), None, true));
|
|
||||||
allow_err!(rdev::simulate_code(Some(vk as _), None, false));
|
|
||||||
for pos in 0..mod_len {
|
|
||||||
let rpos = mod_len - 1 - pos;
|
|
||||||
if flag & (0x0001 << rpos) != 0 {
|
|
||||||
allow_err!(rdev::simulate(&EventType::KeyRelease(modifiers[rpos])));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user