try out unicode if key_down fail
This commit is contained in:
parent
b526bf4a67
commit
2724bd4000
@ -354,9 +354,13 @@ impl KeyboardControllable for Enigo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn key_down(&mut self, key: Key) -> crate::ResultType {
|
fn key_down(&mut self, key: Key) -> crate::ResultType {
|
||||||
|
let code = self.key_to_keycode(key);
|
||||||
|
if code == 0 {
|
||||||
|
return Err("".into());
|
||||||
|
}
|
||||||
if let Some(src) = self.event_source.as_ref() {
|
if let Some(src) = self.event_source.as_ref() {
|
||||||
if let Ok(event) =
|
if let Ok(event) =
|
||||||
CGEvent::new_keyboard_event(src.clone(), self.key_to_keycode(key), true)
|
CGEvent::new_keyboard_event(src.clone(), code, true)
|
||||||
{
|
{
|
||||||
self.post(event);
|
self.post(event);
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,11 @@ impl KeyboardControllable for Enigo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn key_down(&mut self, key: Key) -> crate::ResultType {
|
fn key_down(&mut self, key: Key) -> crate::ResultType {
|
||||||
let res = keybd_event(0, self.key_to_keycode(key), 0);
|
let code = self.key_to_keycode(key);
|
||||||
|
if code == 0 || code == 65535 {
|
||||||
|
return Err("".into());
|
||||||
|
}
|
||||||
|
let res = keybd_event(0, code, 0);
|
||||||
if res == 0 {
|
if res == 0 {
|
||||||
let err = get_error();
|
let err = get_error();
|
||||||
if !err.is_empty() {
|
if !err.is_empty() {
|
||||||
|
@ -684,11 +684,22 @@ fn handle_key_(evt: &KeyEvent) {
|
|||||||
}
|
}
|
||||||
Some(key_event::Union::chr(chr)) => {
|
Some(key_event::Union::chr(chr)) => {
|
||||||
if evt.down {
|
if evt.down {
|
||||||
allow_err!(en.key_down(get_layout(chr)));
|
if en.key_down(get_layout(chr)).is_ok() {
|
||||||
KEYS_DOWN
|
KEYS_DOWN
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.insert(chr as u64 + KEY_CHAR_START, Instant::now());
|
.insert(chr as u64 + KEY_CHAR_START, Instant::now());
|
||||||
|
} else {
|
||||||
|
if let Ok(chr) = char::try_from(chr) {
|
||||||
|
let mut x = chr.to_string();
|
||||||
|
if get_modifier_state(Key::Shift, &mut en)
|
||||||
|
|| get_modifier_state(Key::CapsLock, &mut en)
|
||||||
|
{
|
||||||
|
x = x.to_uppercase();
|
||||||
|
}
|
||||||
|
en.key_sequence(&x);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
en.key_up(get_layout(chr));
|
en.key_up(get_layout(chr));
|
||||||
KEYS_DOWN
|
KEYS_DOWN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user