diff --git a/base/keycodes.hpp b/base/keycodes.hpp index d9d7f654..73f383ea 100644 --- a/base/keycodes.hpp +++ b/base/keycodes.hpp @@ -40,11 +40,12 @@ #define GAMEPAD_BUTTON_START 0x1006 #define TOUCH_DOUBLE_TAP 0x1100 -#elif defined(VK_USE_PLATFORM_IOS_MVK) -// Use numeric keys instead of function keys. -// Use main keyboard plus/minus instead of keypad plus/minus -// Use Delete key instead of Escape key. -#define KEY_ESCAPE 0x33 +#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK)) +#if !defined(VK_EXAMPLE_XCODE_GENERATED) +// For iOS and macOS pre-configured Xcode example project: Use character keycodes +// - Use numeric keys instead of function keys. +#define KEY_DELETE 0x7F +#define KEY_ESCAPE 0x1B #define KEY_F1 '1' #define KEY_F2 '2' #define KEY_F3 '3' @@ -62,14 +63,18 @@ #define KEY_L 'l' #define KEY_N 'n' #define KEY_O 'o' +#define KEY_Q 'q' #define KEY_T 't' +#define KEY_Z 'z' -#elif defined(VK_USE_PLATFORM_MACOS_MVK) -// For compatibility with iOS UX and absent keypad on MacBook: +#else // defined(VK_EXAMPLE_XCODE_GENERATED) +// For cross-platform cmake-generated Xcode project: Use ANSI keyboard keycodes // - Use numeric keys instead of function keys // - Use main keyboard plus/minus instead of keypad plus/minus -// - Use Delete key instead of Escape key -#define KEY_ESCAPE 0x33 +// Note: Carbon kVK_* definitions are used instead of these in vulkanexamplebase.cpp +// Currently only KEY_SPACE and KEY_KPADD are used in textoverlay.cpp example +#define KEY_DELETE 0x33 +#define KEY_ESCAPE 0x35 #define KEY_F1 0x12 #define KEY_F2 0x13 #define KEY_F3 0x14 @@ -87,7 +92,10 @@ #define KEY_L 0x25 #define KEY_N 0x2D #define KEY_O 0x1F +#define KEY_Q 0x0C #define KEY_T 0x11 +#define KEY_Z 0x06 +#endif #elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) #define KEY_ESCAPE DIKS_ESCAPE @@ -137,4 +145,4 @@ #define KEY_N 0x39 #define KEY_O 0x20 #define KEY_T 0x1C -#endif \ No newline at end of file +#endif diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 28016be2..bbafb239 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -1601,6 +1601,7 @@ static CVReturn displayLinkOutputCallback(CVDisplayLinkRef displayLink, const CV case kVK_ANSI_P: vulkanExample->paused = !vulkanExample->paused; break; + case kVK_Delete: // support keyboards with no escape key case kVK_Escape: [NSApp terminate:nil]; break; @@ -1617,6 +1618,7 @@ static CVReturn displayLinkOutputCallback(CVDisplayLinkRef displayLink, const CV vulkanExample->camera.keys.right = true; break; default: + vulkanExample->keyPressed(event.keyCode); // handle example-specific key press events break; } } @@ -1633,9 +1635,9 @@ static CVReturn displayLinkOutputCallback(CVDisplayLinkRef displayLink, const CV break; case kVK_ANSI_A: vulkanExample->camera.keys.left = false; - break; - case kVK_ANSI_D: - vulkanExample->camera.keys.right = false; + break; + case kVK_ANSI_D: + vulkanExample->camera.keys.right = false; break; default: break; diff --git a/xcode/MVKExample.cpp b/xcode/MVKExample.cpp index ca561249..53c73a23 100644 --- a/xcode/MVKExample.cpp +++ b/xcode/MVKExample.cpp @@ -21,11 +21,10 @@ void MVKExample::setRefreshPeriod(double refreshPeriod) { // SRS - set Vul _vulkanExample->refreshPeriod = refreshPeriod; } -void MVKExample::keyPressed(uint32_t keyChar) { // SRS - handle iOS virtual screen keyboard presses +void MVKExample::keyPressed(uint32_t keyChar) { // SRS - handle keyboard key presses only (e.g. Pause, Space, etc) switch (keyChar) { - case 'p': - case 'P': + case KEY_P: _vulkanExample->paused = !_vulkanExample->paused; break; default: @@ -34,34 +33,25 @@ void MVKExample::keyPressed(uint32_t keyChar) { // SRS - handle iOS virtual } } -void MVKExample::keyDown(uint32_t keyChar) { // SRS - handle physical keyboard key down/up actions +void MVKExample::keyDown(uint32_t keyChar) { // SRS - handle physical keyboard key down/up actions and presses switch (keyChar) { - case 'p': - case 'P': - _vulkanExample->paused = !_vulkanExample->paused; - break; - case 'w': - case 'W': - case 'z': // for French AZERTY keyboards - case 'Z': + case KEY_W: + case KEY_Z: // for French AZERTY keyboards _vulkanExample->camera.keys.up = true; break; - case 's': - case 'S': + case KEY_S: _vulkanExample->camera.keys.down = true; break; - case 'a': - case 'A': - case 'q': // for French AZERTY keyboards - case 'Q': + case KEY_A: + case KEY_Q: // for French AZERTY keyboards _vulkanExample->camera.keys.left = true; break; - case 'd': - case 'D': + case KEY_D: _vulkanExample->camera.keys.right = true; break; default: + MVKExample::keyPressed(keyChar); break; } } @@ -69,24 +59,18 @@ void MVKExample::keyDown(uint32_t keyChar) { // SRS - handle physical keyboa void MVKExample::keyUp(uint32_t keyChar) { switch (keyChar) { - case 'w': - case 'W': - case 'z': // for French AZERTY keyboards - case 'Z': + case KEY_W: + case KEY_Z: // for French AZERTY keyboards _vulkanExample->camera.keys.up = false; break; - case 's': - case 'S': + case KEY_S: _vulkanExample->camera.keys.down = false; break; - case 'a': - case 'A': - case 'q': // for French AZERTY keyboards - case 'Q': + case KEY_A: + case KEY_Q: // for French AZERTY keyboards _vulkanExample->camera.keys.left = false; break; - case 'd': - case 'D': + case KEY_D: _vulkanExample->camera.keys.right = false; break; default: diff --git a/xcode/ios/DemoViewController.mm b/xcode/ios/DemoViewController.mm index 616ba39f..2fa3d098 100644 --- a/xcode/ios/DemoViewController.mm +++ b/xcode/ios/DemoViewController.mm @@ -97,13 +97,13 @@ const std::string getAssetPath() { // A key on the keyboard has been pressed. -(void) insertText: (NSString*) text { - unichar keychar = (text.length > 0) ? [text characterAtIndex: 0] : 0; + unichar keychar = (text.length > 0) ? [text.lowercaseString characterAtIndex: 0] : 0; _mvkExample->keyPressed(keychar); } // The delete backward key has been pressed. -(void) deleteBackward { - _mvkExample->keyPressed(0x7F); + _mvkExample->keyPressed(KEY_DELETE); } diff --git a/xcode/macos/DemoViewController.mm b/xcode/macos/DemoViewController.mm index ea33c1bd..333e0fe0 100644 --- a/xcode/macos/DemoViewController.mm +++ b/xcode/macos/DemoViewController.mm @@ -91,13 +91,13 @@ MVKExample* _mvkExample; // SRS - Handle keyboard events -(void) keyDown:(NSEvent*) theEvent { NSString *text = [theEvent charactersIgnoringModifiers]; - unichar keychar = (text.length > 0) ? [text characterAtIndex: 0] : 0; + unichar keychar = (text.length > 0) ? [text.lowercaseString characterAtIndex: 0] : 0; _mvkExample->keyDown(keychar); } -(void) keyUp:(NSEvent*) theEvent { NSString *text = [theEvent charactersIgnoringModifiers]; - unichar keychar = (text.length > 0) ? [text characterAtIndex: 0] : 0; + unichar keychar = (text.length > 0) ? [text.lowercaseString characterAtIndex: 0] : 0; _mvkExample->keyUp(keychar); }