-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support keycode translation on macos shell
Differential Revision: D68856456 fbshipit-source-id: b9080d64ad0a75cd406a59d0cd31982c39fb5418
- Loading branch information
1 parent
8df2bb5
commit c60cc8f
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "KeyCodeTranslator.h" | ||
|
||
#include <igl/Macros.h> | ||
|
||
#if IGL_PLATFORM_APPLE | ||
namespace { | ||
enum KeyModifiers { | ||
kVK_Return = 0x24, | ||
kVK_Tab = 0x30, | ||
kVK_Delete = 0x33, | ||
kVK_Escape = 0x35, | ||
kVK_Shift = 0x38, | ||
kVK_Option = 0x3A, | ||
kVK_Control = 0x3B, | ||
}; | ||
|
||
IGL_MAYBE_UNUSED ImGuiKey keyFromShellKeyEventApple(igl::shell::KeyEvent event) { | ||
KeyModifiers keyCode = (KeyModifiers)event.key; | ||
|
||
switch (keyCode) { | ||
case KeyModifiers::kVK_Return: | ||
return ImGuiKey_Enter; | ||
case KeyModifiers::kVK_Tab: | ||
return ImGuiKey_Tab; | ||
case KeyModifiers::kVK_Delete: | ||
return ImGuiKey_Backspace; | ||
case KeyModifiers::kVK_Escape: | ||
return ImGuiKey_Escape; | ||
case KeyModifiers::kVK_Shift: | ||
return ImGuiKey_LeftShift; | ||
case KeyModifiers::kVK_Option: | ||
return ImGuiKey_LeftAlt; | ||
default: | ||
return (ImGuiKey)keyCode; | ||
} | ||
} | ||
} // namespace | ||
#endif | ||
|
||
namespace iglu::imgui { | ||
ImGuiKey keyFromShellKeyEvent(igl::shell::KeyEvent event) { | ||
#if IGL_PLATFORM_APPLE | ||
return keyFromShellKeyEventApple(event); | ||
#endif | ||
return (ImGuiKey)event.key; | ||
} | ||
} // namespace iglu::imgui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "imgui.h" | ||
#include <shell/shared/input/KeyListener.h> | ||
|
||
namespace iglu::imgui { | ||
ImGuiKey keyFromShellKeyEvent(igl::shell::KeyEvent event); | ||
} // namespace iglu::imgui |