mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2025-01-11 03:21:32 +11:00
Fixed F-keys not working correctly on Mac
This commit is contained in:
parent
7865b87c14
commit
3565e1cb3f
|
@ -2,6 +2,10 @@
|
|||
|
||||
This project follows semantic versioning.
|
||||
|
||||
### v0.5.2 (2016-04-29)
|
||||
|
||||
- [fixed] On Mac shortcuts using F1-F12 wasn't working correctly.
|
||||
|
||||
### v0.5.1 (2016-04-25)
|
||||
|
||||
- [fixed] ```get_window_handle``` would return an invalid value on Unix. Now fixed.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "minifb"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
license = "MIT/Apache-2.0"
|
||||
authors = ["Daniel Collin <daniel@collin.com>"]
|
||||
description = "Cross-platform window setup with optional bitmap rendering"
|
||||
|
|
|
@ -14,7 +14,7 @@ Usage
|
|||
```toml
|
||||
# Cargo.toml
|
||||
[dependencies]
|
||||
minifb = "0.5.1"
|
||||
minifb = "0.5.2"
|
||||
```
|
||||
|
||||
Example
|
||||
|
|
|
@ -31,16 +31,19 @@ fn main() {
|
|||
let sub_menu = vec![
|
||||
Menu {
|
||||
name: "Color 0",
|
||||
key: Key::F1,
|
||||
id: COLOR_0_ID,
|
||||
..Menu::default()
|
||||
},
|
||||
Menu {
|
||||
name: "Color 1",
|
||||
key: Key::F2,
|
||||
id: COLOR_1_ID,
|
||||
..Menu::default()
|
||||
},
|
||||
Menu {
|
||||
name: "Color 2",
|
||||
key: Key::F12,
|
||||
id: COLOR_2_ID,
|
||||
..Menu::default()
|
||||
},
|
||||
|
|
|
@ -266,6 +266,14 @@ const uint32_t MENU_KEY_ALT = 16;
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NSString* get_string_for_key(uint32_t t) {
|
||||
unichar c = (unichar)t;
|
||||
NSString* key = [NSString stringWithCharacters:&c length:1];
|
||||
return key;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void build_submenu(NSMenu* menu, MenuDesc* desc)
|
||||
{
|
||||
[menu removeAllItems];
|
||||
|
@ -293,6 +301,8 @@ void build_submenu(NSMenu* menu, MenuDesc* desc)
|
|||
else
|
||||
{
|
||||
int mask = 0;
|
||||
NSString* key = 0;
|
||||
|
||||
NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(onMenuPress:) keyEquivalent:@""];
|
||||
[newItem setTag:desc->menu_id];
|
||||
|
||||
|
@ -309,15 +319,30 @@ void build_submenu(NSMenu* menu, MenuDesc* desc)
|
|||
mask |= NSAlternateKeyMask;
|
||||
}
|
||||
|
||||
if (desc->key != 0x7f) {
|
||||
NSString* key = convert_key_code_to_string(desc->key);
|
||||
|
||||
if (key) {
|
||||
[newItem setKeyEquivalentModifierMask: mask];
|
||||
[newItem setKeyEquivalent:key];
|
||||
switch (desc->key) {
|
||||
case 0x7a: { key = get_string_for_key(NSF1FunctionKey); break; } // F1
|
||||
case 0x78: { key = get_string_for_key(NSF2FunctionKey); break; } // F2
|
||||
case 0x63: { key = get_string_for_key(NSF3FunctionKey); break; } // F3
|
||||
case 0x76: { key = get_string_for_key(NSF4FunctionKey); break; } // F4
|
||||
case 0x60: { key = get_string_for_key(NSF5FunctionKey); break; } // F5
|
||||
case 0x61: { key = get_string_for_key(NSF6FunctionKey); break; } // F6
|
||||
case 0x62: { key = get_string_for_key(NSF7FunctionKey); break; } // F7
|
||||
case 0x64: { key = get_string_for_key(NSF8FunctionKey); break; } // F8
|
||||
case 0x65: { key = get_string_for_key(NSF9FunctionKey); break; } // F9
|
||||
case 0x6d: { key = get_string_for_key(NSF10FunctionKey); break; } // F10
|
||||
case 0x67: { key = get_string_for_key(NSF11FunctionKey); break; } // F11
|
||||
case 0x6f: { key = get_string_for_key(NSF12FunctionKey); break; } // F12
|
||||
case 0x7f: break;
|
||||
default: {
|
||||
key = convert_key_code_to_string(desc->key);
|
||||
}
|
||||
}
|
||||
|
||||
if (key) {
|
||||
[newItem setKeyEquivalentModifierMask: mask];
|
||||
[newItem setKeyEquivalent:key];
|
||||
}
|
||||
|
||||
if (desc->enabled) {
|
||||
[newItem setEnabled:YES];
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue