Skip to content

Commit

Permalink
Merge pull request #310 from pentamassiv/currentKeyboardLayoutASCII
Browse files Browse the repository at this point in the history
macOS: Add fallback to ASCII-capable keyboard layout for handling non-standard input sources
  • Loading branch information
pentamassiv authored Aug 28, 2024
2 parents d23074c + 55f4404 commit 20534bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- all: `Key::PrintScr`
- all: There finally are some tests in the CI to increase the development speed and prevent regressions
- win, macOS: Allow marking events that were created by enigo. Have a look at the additional field of the `Settings` struct and the new method `get_marker_value` of the `enigo` struct (only available on Windows and macOS)
- macOS: Fallback to ASCII-capable keyboard layout for handling non-standard input sources

## Fixed
win: Respect the language of the current window to determine the which scancodes to send
Expand Down
10 changes: 10 additions & 0 deletions src/macos/macos_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const kCFStringEncodingUTF8: u32 = 0x0800_0100;
extern "C" {
fn TISCopyCurrentKeyboardInputSource() -> TISInputSourceRef;
fn TISCopyCurrentKeyboardLayoutInputSource() -> TISInputSourceRef;
fn TISCopyCurrentASCIICapableKeyboardLayoutInputSource() -> TISInputSourceRef;

#[allow(non_upper_case_globals)]
static kTISPropertyUnicodeKeyLayoutData: CFStringRef;
Expand Down Expand Up @@ -848,6 +849,15 @@ fn create_string_for_key(keycode: u16, modifier: u32) -> CFStringRef {
};
debug_assert!(!layout_data.is_null());
}
if layout_data.is_null() {
debug!("TISGetInputSourceProperty(current_keyboard, kTISPropertyUnicodeKeyLayoutData) returned NULL again");
current_keyboard = unsafe { TISCopyCurrentASCIICapableKeyboardLayoutInputSource() };
layout_data = unsafe {
TISGetInputSourceProperty(current_keyboard, kTISPropertyUnicodeKeyLayoutData)
};
debug_assert!(!layout_data.is_null());
debug!("Using layout of the TISCopyCurrentASCIICapableKeyboardLayoutInputSource");
}
let keyboard_layout = unsafe { CFDataGetBytePtr(layout_data) };

let mut keys_down: UInt32 = 0;
Expand Down

0 comments on commit 20534bc

Please sign in to comment.