Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key handling improvements #12549

Merged
merged 20 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions native/Avalonia.Native/src/OSX/AvnView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -447,24 +447,25 @@ - (void)mouseExited:(NSEvent *)event

- (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type
{
if([self ignoreUserInput: false])
if([self ignoreUserInput: false] || _parent == nullptr)
{
return;
}

auto key = s_KeyMap[[event keyCode]];
auto scanCode = [event keyCode];
auto key = VirtualKeyFromScanCode(scanCode, [event modifierFlags]);
auto physicalKey = PhysicalKeyFromScanCode(scanCode);
auto keySymbol = KeySymbolFromScanCode(scanCode, [event modifierFlags]);
auto keySymbolUtf8 = keySymbol == nullptr ? nullptr : [keySymbol UTF8String];

uint64_t timestamp = static_cast<uint64_t>([event timestamp] * 1000);
auto timestamp = static_cast<uint64_t>([event timestamp] * 1000);
auto modifiers = [self getModifiers:[event modifierFlags]];

if(_parent != nullptr)
{
auto handled = _parent->BaseEvents->RawKeyEvent(type, timestamp, modifiers, key);
if (key != LeftCtrl && key != RightCtrl) {
_lastKeyHandled = handled;
} else {
_lastKeyHandled = false;
}
auto handled = _parent->BaseEvents->RawKeyEvent(type, timestamp, modifiers, key, physicalKey, keySymbolUtf8);
if (key != AvnKeyLeftCtrl && key != AvnKeyRightCtrl) {
_lastKeyHandled = handled;
} else {
_lastKeyHandled = false;
}
}

Expand Down
11 changes: 6 additions & 5 deletions native/Avalonia.Native/src/OSX/KeyTransform.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef keytransform_h
#define keytransform_h

#import <cstdint>
#include "common.h"
#include <map>

extern std::map<int, AvnKey> s_KeyMap;
AvnPhysicalKey PhysicalKeyFromScanCode(uint16_t scanCode);

extern std::map<AvnKey, int> s_AvnKeyMap;
AvnKey VirtualKeyFromScanCode(uint16_t scanCode, NSEventModifierFlags modifierFlags);

extern std::map<int, const char*> s_QwertyKeyMap;
NSString* KeySymbolFromScanCode(uint16_t scanCode, NSEventModifierFlags modifierFlags);

extern std::map<AvnKey, int> s_UnicodeKeyMap;
uint16_t MenuCharFromVirtualKey(AvnKey key);

#endif
Loading