fix: 将键盘事件检测从keyCode改为scancode
统一使用scancode作为键盘事件的检测标准,提高跨平台兼容性
This commit is contained in:
parent
efc9961d2d
commit
a78e6f7a05
|
|
@ -318,7 +318,7 @@ auto eventService = app.events();
|
|||
// 键盘事件
|
||||
eventService->addListener(EventType::KeyPress, [](Event& e) {
|
||||
auto& key = std::get<KeyEvent>(e.data);
|
||||
if (key.keyCode == static_cast<int>(Key::Escape)) {
|
||||
if (key.scancode == static_cast<int>(Key::Escape)) {
|
||||
Application::get().quit();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -495,7 +495,7 @@ auto eventService = app.events();
|
|||
// 监听键盘事件
|
||||
eventService->addListener(EventType::KeyPress, [](Event& e) {
|
||||
auto& key = std::get<KeyEvent>(e.data);
|
||||
if (key.keyCode == static_cast<int>(Key::Escape)) {
|
||||
if (key.scancode == static_cast<int>(Key::Escape)) {
|
||||
Application::get().quit();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -314,12 +314,12 @@ public:
|
|||
addListener(EventType::KeyPress, [](Event& e) {
|
||||
auto& key = std::get<KeyEvent>(e.data);
|
||||
|
||||
if (key.keyCode == static_cast<int>(Key::Escape)) {
|
||||
if (key.scancode == static_cast<int>(Key::Escape)) {
|
||||
e.handled = true;
|
||||
Application::get().quit();
|
||||
}
|
||||
|
||||
if (key.keyCode == static_cast<int>(Key::Space)) {
|
||||
if (key.scancode == static_cast<int>(Key::Space)) {
|
||||
E2D_LOG_INFO("Space pressed!");
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ int main(int argc, char *argv[]) {
|
|||
eventService->addListener(EventType::KeyPress, [](Event &e) {
|
||||
auto &keyEvent = std::get<KeyEvent>(e.data);
|
||||
|
||||
if (keyEvent.keyCode == static_cast<int>(Key::Escape)) {
|
||||
if (keyEvent.scancode == static_cast<int>(Key::Escape)) {
|
||||
e.handled = true;
|
||||
Application::get().quit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public:
|
|||
addListener(EventType::KeyPress, [](Event &e) {
|
||||
auto &keyEvent = std::get<KeyEvent>(e.data);
|
||||
|
||||
if (keyEvent.keyCode == static_cast<int>(Key::Escape)) {
|
||||
if (keyEvent.scancode == static_cast<int>(Key::Escape)) {
|
||||
e.handled = true;
|
||||
E2D_LOG_INFO("ESC !!!exit");
|
||||
Application::get().quit();
|
||||
|
|
|
|||
Loading…
Reference in New Issue