@@ -377,6 +377,7 @@ pub(crate) fn physicalkey_to_scancode(physical_key: PhysicalKey) -> Option<u32>
377
377
KeyCode :: KeyX => Some ( 0x07 ) ,
378
378
KeyCode :: KeyC => Some ( 0x08 ) ,
379
379
KeyCode :: KeyV => Some ( 0x09 ) ,
380
+ KeyCode :: IntlBackslash => Some ( 0x0a ) ,
380
381
KeyCode :: KeyB => Some ( 0x0b ) ,
381
382
KeyCode :: KeyQ => Some ( 0x0c ) ,
382
383
KeyCode :: KeyW => Some ( 0x0d ) ,
@@ -422,18 +423,21 @@ pub(crate) fn physicalkey_to_scancode(physical_key: PhysicalKey) -> Option<u32>
422
423
KeyCode :: SuperRight => Some ( 0x36 ) ,
423
424
KeyCode :: SuperLeft => Some ( 0x37 ) ,
424
425
KeyCode :: ShiftLeft => Some ( 0x38 ) ,
426
+ KeyCode :: CapsLock => Some ( 0x39 ) ,
425
427
KeyCode :: AltLeft => Some ( 0x3a ) ,
426
428
KeyCode :: ControlLeft => Some ( 0x3b ) ,
427
429
KeyCode :: ShiftRight => Some ( 0x3c ) ,
428
430
KeyCode :: AltRight => Some ( 0x3d ) ,
429
431
KeyCode :: ControlRight => Some ( 0x3e ) ,
432
+ KeyCode :: Fn => Some ( 0x3f ) ,
430
433
KeyCode :: F17 => Some ( 0x40 ) ,
431
434
KeyCode :: NumpadDecimal => Some ( 0x41 ) ,
432
435
KeyCode :: NumpadMultiply => Some ( 0x43 ) ,
433
436
KeyCode :: NumpadAdd => Some ( 0x45 ) ,
434
437
KeyCode :: NumLock => Some ( 0x47 ) ,
435
- KeyCode :: AudioVolumeUp => Some ( 0x49 ) ,
436
- KeyCode :: AudioVolumeDown => Some ( 0x4a ) ,
438
+ KeyCode :: AudioVolumeUp => Some ( 0x48 ) ,
439
+ KeyCode :: AudioVolumeDown => Some ( 0x49 ) ,
440
+ KeyCode :: AudioVolumeMute => Some ( 0x4a ) ,
437
441
KeyCode :: NumpadDivide => Some ( 0x4b ) ,
438
442
KeyCode :: NumpadEnter => Some ( 0x4c ) ,
439
443
KeyCode :: NumpadSubtract => Some ( 0x4e ) ,
@@ -452,17 +456,22 @@ pub(crate) fn physicalkey_to_scancode(physical_key: PhysicalKey) -> Option<u32>
452
456
KeyCode :: Numpad8 => Some ( 0x5b ) ,
453
457
KeyCode :: Numpad9 => Some ( 0x5c ) ,
454
458
KeyCode :: IntlYen => Some ( 0x5d ) ,
459
+ KeyCode :: IntlRo => Some ( 0x5e ) ,
460
+ KeyCode :: NumpadComma => Some ( 0x5f ) ,
455
461
KeyCode :: F5 => Some ( 0x60 ) ,
456
462
KeyCode :: F6 => Some ( 0x61 ) ,
457
463
KeyCode :: F7 => Some ( 0x62 ) ,
458
464
KeyCode :: F3 => Some ( 0x63 ) ,
459
465
KeyCode :: F8 => Some ( 0x64 ) ,
460
466
KeyCode :: F9 => Some ( 0x65 ) ,
467
+ KeyCode :: Lang2 => Some ( 0x66 ) ,
461
468
KeyCode :: F11 => Some ( 0x67 ) ,
469
+ KeyCode :: Lang1 => Some ( 0x68 ) ,
462
470
KeyCode :: F13 => Some ( 0x69 ) ,
463
471
KeyCode :: F16 => Some ( 0x6a ) ,
464
472
KeyCode :: F14 => Some ( 0x6b ) ,
465
473
KeyCode :: F10 => Some ( 0x6d ) ,
474
+ KeyCode :: ContextMenu => Some ( 0x6e ) ,
466
475
KeyCode :: F12 => Some ( 0x6f ) ,
467
476
KeyCode :: F15 => Some ( 0x71 ) ,
468
477
KeyCode :: Insert => Some ( 0x72 ) ,
@@ -478,11 +487,26 @@ pub(crate) fn physicalkey_to_scancode(physical_key: PhysicalKey) -> Option<u32>
478
487
KeyCode :: ArrowRight => Some ( 0x7c ) ,
479
488
KeyCode :: ArrowDown => Some ( 0x7d ) ,
480
489
KeyCode :: ArrowUp => Some ( 0x7e ) ,
490
+ KeyCode :: Power => Some ( 0x7f ) ,
481
491
_ => None ,
482
492
}
483
493
}
484
494
485
495
pub ( crate ) fn scancode_to_physicalkey ( scancode : u32 ) -> PhysicalKey {
496
+ // Follows what Chromium and Firefox do:
497
+ // https://chromium.googlesource.com/chromium/src.git/+/3e1a26c44c024d97dc9a4c09bbc6a2365398ca2c/ui/events/keycodes/dom/dom_code_data.inc
498
+ // https://searchfox.org/mozilla-central/rev/c597e9c789ad36af84a0370d395be066b7dc94f4/widget/NativeKeyToDOMCodeName.h
499
+ //
500
+ // See also:
501
+ // Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h
502
+ //
503
+ // Also see https://developer.apple.com/documentation/appkit/function-key-unicode-values:
504
+ //
505
+ // > the system handles some function keys at a lower level and your app never sees them.
506
+ // > Examples include the Volume Up key, Volume Down key, Volume Mute key, Eject key, and
507
+ // > Function key found on many Macs.
508
+ //
509
+ // So the handling of some of these is mostly for show.
486
510
PhysicalKey :: Code ( match scancode {
487
511
0x00 => KeyCode :: KeyA ,
488
512
0x01 => KeyCode :: KeyS ,
@@ -494,7 +518,11 @@ pub(crate) fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey {
494
518
0x07 => KeyCode :: KeyX ,
495
519
0x08 => KeyCode :: KeyC ,
496
520
0x09 => KeyCode :: KeyV ,
497
- // 0x0a => World 1,
521
+ // This key is typically located near LeftShift key, roughly the same location as backquote
522
+ // (`) on Windows' US layout.
523
+ //
524
+ // The keycap varies on international keyboards.
525
+ 0x0a => KeyCode :: IntlBackslash ,
498
526
0x0b => KeyCode :: KeyB ,
499
527
0x0c => KeyCode :: KeyQ ,
500
528
0x0d => KeyCode :: KeyW ,
@@ -536,7 +564,7 @@ pub(crate) fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey {
536
564
0x31 => KeyCode :: Space ,
537
565
0x32 => KeyCode :: Backquote ,
538
566
0x33 => KeyCode :: Backspace ,
539
- // 0x34 => unknown,
567
+ // 0x34 => unknown, // kVK_Powerbook_KeypadEnter
540
568
0x35 => KeyCode :: Escape ,
541
569
0x36 => KeyCode :: SuperRight ,
542
570
0x37 => KeyCode :: SuperLeft ,
@@ -555,15 +583,10 @@ pub(crate) fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey {
555
583
// 0x44 => unknown,
556
584
0x45 => KeyCode :: NumpadAdd ,
557
585
// 0x46 => unknown,
558
- 0x47 => KeyCode :: NumLock ,
559
- // 0x48 => KeyCode::NumpadClear,
560
-
561
- // TODO: (Artur) for me, kVK_VolumeUp is 0x48
562
- // macOS 10.11
563
- // /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/
564
- // Versions/A/Headers/Events.h
565
- 0x49 => KeyCode :: AudioVolumeUp ,
566
- 0x4a => KeyCode :: AudioVolumeDown ,
586
+ 0x47 => KeyCode :: NumLock , // kVK_ANSI_KeypadClear
587
+ 0x48 => KeyCode :: AudioVolumeUp ,
588
+ 0x49 => KeyCode :: AudioVolumeDown ,
589
+ 0x4a => KeyCode :: AudioVolumeMute ,
567
590
0x4b => KeyCode :: NumpadDivide ,
568
591
0x4c => KeyCode :: NumpadEnter ,
569
592
// 0x4d => unknown,
@@ -583,23 +606,23 @@ pub(crate) fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey {
583
606
0x5b => KeyCode :: Numpad8 ,
584
607
0x5c => KeyCode :: Numpad9 ,
585
608
0x5d => KeyCode :: IntlYen ,
586
- // 0x5e => JIS Ro ,
587
- // 0x5f => unknown ,
609
+ 0x5e => KeyCode :: IntlRo ,
610
+ 0x5f => KeyCode :: NumpadComma ,
588
611
0x60 => KeyCode :: F5 ,
589
612
0x61 => KeyCode :: F6 ,
590
613
0x62 => KeyCode :: F7 ,
591
614
0x63 => KeyCode :: F3 ,
592
615
0x64 => KeyCode :: F8 ,
593
616
0x65 => KeyCode :: F9 ,
594
- // 0x66 => JIS Eisuu (macOS) ,
617
+ 0x66 => KeyCode :: Lang2 ,
595
618
0x67 => KeyCode :: F11 ,
596
- // 0x68 => JIS Kanna (macOS) ,
619
+ 0x68 => KeyCode :: Lang1 ,
597
620
0x69 => KeyCode :: F13 ,
598
621
0x6a => KeyCode :: F16 ,
599
622
0x6b => KeyCode :: F14 ,
600
623
// 0x6c => unknown,
601
624
0x6d => KeyCode :: F10 ,
602
- // 0x6e => unknown ,
625
+ 0x6e => KeyCode :: ContextMenu ,
603
626
0x6f => KeyCode :: F12 ,
604
627
// 0x70 => unknown,
605
628
0x71 => KeyCode :: F15 ,
@@ -616,11 +639,7 @@ pub(crate) fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey {
616
639
0x7c => KeyCode :: ArrowRight ,
617
640
0x7d => KeyCode :: ArrowDown ,
618
641
0x7e => KeyCode :: ArrowUp ,
619
- // 0x7f => unknown,
620
-
621
- // 0xA is the caret (^) an macOS's German QERTZ layout. This key is at the same location as
622
- // backquote (`) on Windows' US layout.
623
- 0xa => KeyCode :: Backquote ,
642
+ 0x7f => KeyCode :: Power , // On 10.7 and 10.8 only
624
643
_ => return PhysicalKey :: Unidentified ( NativeKeyCode :: MacOS ( scancode as u16 ) ) ,
625
644
} )
626
645
}
0 commit comments