another test
This commit is contained in:
parent
bfca616a16
commit
f9ef7c59db
@ -10,7 +10,7 @@ revert_keymap_index = 0
|
|||||||
|
|
||||||
# this is the default index to use when the program first starts
|
# this is the default index to use when the program first starts
|
||||||
# in this case, 2 means Unix Programmer Dvorak
|
# in this case, 2 means Unix Programmer Dvorak
|
||||||
default_keymap_index = 1
|
default_keymap_index = 2
|
||||||
|
|
||||||
# these are the keymaps available, you can add as many as you want or re-order them, just be aware the mapping is
|
# these are the keymaps available, you can add as many as you want or re-order them, just be aware the mapping is
|
||||||
# always done from the first one to all subsequent ones, so you probably want to leave QWERTY or similar up top
|
# always done from the first one to all subsequent ones, so you probably want to leave QWERTY or similar up top
|
||||||
|
@ -18,6 +18,7 @@ use lazy_static::lazy_static;
|
|||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use core_graphics::event::CGKeyCode;
|
use core_graphics::event::CGKeyCode;
|
||||||
use core_graphics::event::*;
|
use core_graphics::event::*;
|
||||||
|
use core_graphics::event_source::*;
|
||||||
use core_foundation_sys::*;
|
use core_foundation_sys::*;
|
||||||
use core_foundation_sys::base::*;
|
use core_foundation_sys::base::*;
|
||||||
use core_foundation_sys::runloop::*;
|
use core_foundation_sys::runloop::*;
|
||||||
@ -83,16 +84,47 @@ pub struct Device;
|
|||||||
|
|
||||||
impl Keyboard<CGKeyCode, InputEvent, Option<CGEventRef>> for Device {
|
impl Keyboard<CGKeyCode, InputEvent, Option<CGEventRef>> for Device {
|
||||||
fn send(&self, event: &mut InputEvent) -> Result<Option<CGEventRef>> {
|
fn send(&self, event: &mut InputEvent) -> Result<Option<CGEventRef>> {
|
||||||
|
println!("send orig: {}", event.code());
|
||||||
Ok(Some(event.event))
|
Ok(Some(event.event))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_mod_code(&self, code: CGKeyCode, event: &mut InputEvent) -> Result<Option<CGEventRef>> {
|
fn send_mod_code(&self, code: CGKeyCode, event: &mut InputEvent) -> Result<Option<CGEventRef>> {
|
||||||
// event.value should only ever be UP/DOWN when this method is called
|
// event.value should only ever be UP/DOWN when this method is called
|
||||||
Ok(None)
|
println!("send_mod_code orig: {} code: {}", event.code(), code);
|
||||||
|
//event.event.set_integer_value_field();
|
||||||
|
//unsafe { CGEventSetIntegerValueField(event.event, kCGKeyboardEventKeycode, code as i64) };
|
||||||
|
|
||||||
|
//Ok(Some(event.event))
|
||||||
|
//Ok(None)
|
||||||
|
|
||||||
|
self.send_mod_code_value(code, event.value() == KeyState::UP, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_mod_code_value(&self, code: CGKeyCode, up_not_down: bool, _event: &mut InputEvent) -> Result<Option<CGEventRef>> {
|
fn send_mod_code_value(&self, code: CGKeyCode, up_not_down: bool, event: &mut InputEvent) -> Result<Option<CGEventRef>> {
|
||||||
Ok(None)
|
println!("send_mod_code_value orig: {} code: {}, up_not_down: {}", event.code(), code, up_not_down);
|
||||||
|
|
||||||
|
// https://github.com/enigo-rs/enigo/blob/master/src/macos/macos_impl.rs
|
||||||
|
/*
|
||||||
|
let event_source = CGEventSource::new(CGEventSourceStateID::CombinedSessionState)
|
||||||
|
.expect("Failed creating event source");
|
||||||
|
|
||||||
|
let event =
|
||||||
|
CGEvent::new_keyboard_event(event_source.clone(), code, !up_not_down)
|
||||||
|
.expect("Failed creating event");
|
||||||
|
event.post(CGEventTapLocation::HID);
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsafe { CGEventSetIntegerValueField(event.event, kCGKeyboardEventKeycode, code as i64) };
|
||||||
|
|
||||||
|
|
||||||
|
let flags = unsafe { CGEventGetFlags(event.event) };
|
||||||
|
print_flags(flags);
|
||||||
|
let flags = flags >> NX_DEVICERSHIFTKEYMASK;
|
||||||
|
print_flags(flags);
|
||||||
|
//CGEventSetFlags(event, flags);
|
||||||
|
|
||||||
|
Ok(Some(event.event))
|
||||||
|
//Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn synchronize(&self) -> Result<Option<CGEventRef>> {
|
fn synchronize(&self) -> Result<Option<CGEventRef>> {
|
||||||
@ -148,14 +180,15 @@ pub fn main_res() -> Result<()> {
|
|||||||
//let _ = KEY_MAPPER.lock().unwrap();
|
//let _ = KEY_MAPPER.lock().unwrap();
|
||||||
|
|
||||||
let config = parse_args();
|
let config = parse_args();
|
||||||
//println!("Config: {:?}", config);
|
println!("Config: {:?}", config);
|
||||||
|
|
||||||
let key_map = key_map();
|
let key_map = key_map();
|
||||||
//println!("key_map: {:?}", key_map);
|
println!("key_map: {:?}", key_map);
|
||||||
|
|
||||||
println!("chosen config file: {}", config.config_file);
|
println!("chosen config file: {}", config.config_file);
|
||||||
|
|
||||||
let key_maps = MacOSKeyMaps::from_cfg(&key_map, &config.config_file);
|
let key_maps = MacOSKeyMaps::from_cfg(&key_map, &config.config_file);
|
||||||
|
//println!("key_maps: {}", key_maps);
|
||||||
|
|
||||||
let mask = CGEventMaskBit(kCGEventKeyDown)
|
let mask = CGEventMaskBit(kCGEventKeyDown)
|
||||||
| CGEventMaskBit(kCGEventKeyUp)
|
| CGEventMaskBit(kCGEventKeyUp)
|
||||||
@ -337,6 +370,8 @@ pub const kCGEventTapDisabledByTimeout: CGEventType = 0xFFFFFFFE;
|
|||||||
field: CGEventField,
|
field: CGEventField,
|
||||||
) -> CGKeyCode;
|
) -> CGKeyCode;
|
||||||
|
|
||||||
|
fn CGEventSetIntegerValueField(event: CGEventRef, field: CGEventField, value: i64);
|
||||||
|
|
||||||
/// Create an event tap
|
/// Create an event tap
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
@ -410,6 +445,7 @@ pub const kCGEventTapDisabledByTimeout: CGEventType = 0xFFFFFFFE;
|
|||||||
|
|
||||||
pub fn CGEventGetType(event: CGEventRef) -> CGEventType;
|
pub fn CGEventGetType(event: CGEventRef) -> CGEventType;
|
||||||
pub fn CGEventGetFlags(event: CGEventRef) -> CGEventFlags;
|
pub fn CGEventGetFlags(event: CGEventRef) -> CGEventFlags;
|
||||||
|
pub fn CGEventSetFlags(event: CGEventRef, flags: CGEventFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CGEventFlagNull: u64 = 0;
|
const CGEventFlagNull: u64 = 0;
|
||||||
@ -440,34 +476,37 @@ const NX_DEVICELALTKEYMASK: u64 = 0x00000020;
|
|||||||
const NX_DEVICERALTKEYMASK: u64 = 0x00000040;
|
const NX_DEVICERALTKEYMASK: u64 = 0x00000040;
|
||||||
const NX_DEVICERCTLKEYMASK: u64 = 0x00002000;
|
const NX_DEVICERCTLKEYMASK: u64 = 0x00002000;
|
||||||
|
|
||||||
|
fn print_flags(flags: CGEventFlags) {
|
||||||
|
println!("flags: {}", flags);
|
||||||
|
println!("flags: {:#064b}", flags);
|
||||||
|
|
||||||
|
println!("EventFlags: {:x} ({} {} {} {} {} {} {} {})\n",
|
||||||
|
flags,
|
||||||
|
if (flags & NX_DEVICELCTLKEYMASK) != 0 { "lcontrol" } else { "" },
|
||||||
|
if (flags & NX_DEVICERCTLKEYMASK) != 0 { "rcontrol" } else { "" },
|
||||||
|
if (flags & NX_DEVICELSHIFTKEYMASK) != 0 { "lshift" } else { "" },
|
||||||
|
if (flags & NX_DEVICERSHIFTKEYMASK) != 0 { "rshift" } else { "" },
|
||||||
|
if (flags & NX_DEVICELCMDKEYMASK) != 0 { "lcommand" } else { "" },
|
||||||
|
if (flags & NX_DEVICERCMDKEYMASK) != 0 { "rcommand" } else { "" },
|
||||||
|
if (flags & NX_DEVICELALTKEYMASK) != 0 { "lalt" } else { "" },
|
||||||
|
if (flags & NX_DEVICERALTKEYMASK) != 0 { "ralt" } else { "" },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// This callback will be registered to be invoked from the run loop
|
/// This callback will be registered to be invoked from the run loop
|
||||||
/// to which the event tap is added as a source.
|
/// to which the event tap is added as a source.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub extern fn callback(proxy: Pointer, event_type: CGEventType, event: CGEventRef, key_maps: &mut MacOSKeyMaps)
|
pub extern fn callback(proxy: Pointer, event_type: CGEventType, event: CGEventRef, key_maps: &mut MacOSKeyMaps)
|
||||||
-> CGEventRef {
|
-> CGEventRef {
|
||||||
|
//print_flags(event);
|
||||||
/*
|
/*
|
||||||
println!("+++++++++++++++++++++++++++++++++++++++");
|
println!("+++++++++++++++++++++++++++++++++++++++");
|
||||||
let event_type2 = unsafe { CGEventGetType(event) };
|
let event_type2 = unsafe { CGEventGetType(event) };
|
||||||
println!("event_type2: {}", event_type2);
|
println!("event_type2: {}", event_type2);
|
||||||
|
|
||||||
|
|
||||||
let flags = unsafe { CGEventGetFlags(event) };
|
|
||||||
println!("flags: {}", flags);
|
|
||||||
println!("flags: {:#064b}", flags);
|
|
||||||
|
|
||||||
println!("EventFlagsChanged: {:x} ({} {} {} {} {} {} {} {})\n",
|
|
||||||
flags,
|
|
||||||
if (flags & NX_DEVICELCTLKEYMASK) != 0 { "lcontrol" } else { "" },
|
|
||||||
if (flags & NX_DEVICERCTLKEYMASK) != 0 { "rcontrol" } else { "" },
|
|
||||||
if (flags & NX_DEVICELSHIFTKEYMASK) != 0 { "lshift" } else { "" },
|
|
||||||
if (flags & NX_DEVICERSHIFTKEYMASK) != 0 { "rshift" } else { "" },
|
|
||||||
if (flags & NX_DEVICELCMDKEYMASK) != 0 { "lcommand" } else { "" },
|
|
||||||
if (flags & NX_DEVICERCMDKEYMASK) != 0 { "rcommand" } else { "" },
|
|
||||||
if (flags & NX_DEVICELALTKEYMASK) != 0 { "lalt" } else { "" },
|
|
||||||
if (flags & NX_DEVICERALTKEYMASK) != 0 { "ralt" } else { "" },
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
match event_type {
|
match event_type {
|
||||||
@ -491,22 +530,27 @@ pub extern fn callback(proxy: Pointer, event_type: CGEventType, event: CGEventRe
|
|||||||
event_type,
|
event_type,
|
||||||
event,
|
event,
|
||||||
};
|
};
|
||||||
/*
|
|
||||||
println!("got keyCode: {}", input_event.code());
|
println!("got keyCode: {}", input_event.code());
|
||||||
|
/*
|
||||||
println!("---------------------------------------");
|
println!("---------------------------------------");
|
||||||
*/
|
|
||||||
if input_event.value() == KeyState::DOWN {
|
if input_event.value() == KeyState::DOWN {
|
||||||
let code = input_event.code();
|
let code = input_event.code();
|
||||||
println!("KEY 0x{:04X}", code);
|
println!("KEY 0x{:04X}", code);
|
||||||
write_key_file(code).expect("error writing key file");
|
write_key_file(code).expect("error writing key file");
|
||||||
}
|
}
|
||||||
std::ptr::null_mut()
|
std::ptr::null_mut()
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
//input_event.event.set
|
//input_event.event.set
|
||||||
//input_event.event
|
//input_event.event
|
||||||
//Null.
|
//Null.
|
||||||
//Some(input_event.event)
|
//Some(input_event.event)
|
||||||
//key_maps.send_event(&mut input_event, &DEVICE).expect("macos shouldn't error...")
|
key_maps.send_event(&mut input_event, &DEVICE).expect("macos shouldn't error...")
|
||||||
// .unwrap_or_else(|| std::ptr::null_mut()) // None means return NULL
|
.unwrap_or_else(|| {
|
||||||
|
println!("returning NULL from hook");
|
||||||
|
std::ptr::null_mut()
|
||||||
|
}) // None means return NULL
|
||||||
//let keyCode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
|
//let keyCode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
|
||||||
//println!("got keyCode: {}", keyCode);
|
//println!("got keyCode: {}", keyCode);
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user