Browse Source

Platform: print actual key enum names in application tests.

And for Sdl2Application print both the keycode and keysym, as the
current way with a keycode seems different from what both GLFW and HTML5
does. But the SDL2 scancode also doesn't feel right because compared to
GLFW and HTML5 it swaps Y and Z on my keyboard. SIGH.
pull/638/head
Vladimír Vondruš 2 years ago
parent
commit
46e5f300c1
  1. 131
      src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp
  2. 137
      src/Magnum/Platform/Test/GlfwApplicationTest.cpp
  3. 132
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

131
src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp

@ -46,6 +46,125 @@
namespace Magnum { namespace Platform { namespace Test { namespace { namespace Magnum { namespace Platform { namespace Test { namespace {
Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) {
debug << "Key" << Debug::nospace;
switch(value) {
#define _c(value) case Application::KeyEvent::Key::value: return debug << "::" #value;
_c(Unknown)
_c(LeftShift)
_c(RightShift)
_c(LeftCtrl)
_c(RightCtrl)
_c(LeftAlt)
_c(RightAlt)
_c(LeftSuper)
_c(RightSuper)
_c(Enter)
_c(Esc)
_c(Up)
_c(Down)
_c(Left)
_c(Right)
_c(Home)
_c(End)
_c(PageUp)
_c(PageDown)
_c(Backspace)
_c(Insert)
_c(Delete)
_c(F1)
_c(F2)
_c(F3)
_c(F4)
_c(F5)
_c(F6)
_c(F7)
_c(F8)
_c(F9)
_c(F10)
_c(F11)
_c(F12)
_c(Zero)
_c(One)
_c(Two)
_c(Three)
_c(Four)
_c(Five)
_c(Six)
_c(Seven)
_c(Eight)
_c(Nine)
_c(A)
_c(B)
_c(C)
_c(D)
_c(E)
_c(F)
_c(G)
_c(H)
_c(I)
_c(J)
_c(K)
_c(L)
_c(M)
_c(N)
_c(O)
_c(P)
_c(Q)
_c(R)
_c(S)
_c(T)
_c(U)
_c(V)
_c(W)
_c(X)
_c(Y)
_c(Z)
_c(Space)
_c(Tab)
_c(Quote)
_c(Comma)
_c(Period)
_c(Minus)
_c(Plus)
_c(Slash)
_c(Percent)
_c(Semicolon)
_c(Equal)
_c(LeftBracket)
_c(RightBracket)
_c(Backslash)
_c(Backquote)
_c(CapsLock)
_c(ScrollLock)
_c(NumLock)
_c(PrintScreen)
_c(Pause)
_c(Menu)
_c(NumZero)
_c(NumOne)
_c(NumTwo)
_c(NumThree)
_c(NumFour)
_c(NumFive)
_c(NumSix)
_c(NumSeven)
_c(NumEight)
_c(NumNine)
_c(NumDecimal)
_c(NumDivide)
_c(NumMultiply)
_c(NumSubtract)
_c(NumAdd)
_c(NumEnter)
_c(NumEqual)
#undef _c
}
return debug << "(" << Debug::nospace << Debug::hex << UnsignedInt(value) << Debug::nospace << ")";
}
using namespace Containers::Literals; using namespace Containers::Literals;
using namespace Math::Literals; using namespace Math::Literals;
@ -95,11 +214,7 @@ struct EmscriptenApplicationTest: Platform::Application {
void keyPressEvent(KeyEvent& event) override { void keyPressEvent(KeyEvent& event) override {
{ {
Debug d; Debug d;
if(event.key() != KeyEvent::Key::Unknown) { d << "key press event:" << event.key() << event.keyName();
d << "keyPressEvent(" << Debug::nospace << event.keyName().data() << Debug::nospace << "): ✔";
} else {
d << "keyPressEvent(" << Debug::nospace << event.keyName().data() << Debug::nospace << "): ✘";
}
if(event.modifiers() & KeyEvent::Modifier::Shift) d << "Shift"; if(event.modifiers() & KeyEvent::Modifier::Shift) d << "Shift";
if(event.modifiers() & KeyEvent::Modifier::Ctrl) d << "Ctrl"; if(event.modifiers() & KeyEvent::Modifier::Ctrl) d << "Ctrl";
@ -134,11 +249,7 @@ struct EmscriptenApplicationTest: Platform::Application {
void keyReleaseEvent(KeyEvent& event) override { void keyReleaseEvent(KeyEvent& event) override {
{ {
Debug d; Debug d;
if(event.key() != KeyEvent::Key::Unknown) { d << "key release event:" << event.key() << event.keyName();
d << "keyReleaseEvent(" << Debug::nospace << event.keyName() << Debug::nospace << "): ✔";
} else {
d << "keyReleaseEvent(" << Debug::nospace << event.keyName() << Debug::nospace << "): ✘";
}
if(event.modifiers() & KeyEvent::Modifier::Shift) d << "Shift"; if(event.modifiers() & KeyEvent::Modifier::Shift) d << "Shift";
if(event.modifiers() & KeyEvent::Modifier::Ctrl) d << "Ctrl"; if(event.modifiers() & KeyEvent::Modifier::Ctrl) d << "Ctrl";

137
src/Magnum/Platform/Test/GlfwApplicationTest.cpp

@ -36,6 +36,127 @@
namespace Magnum { namespace Platform { namespace Test { namespace { namespace Magnum { namespace Platform { namespace Test { namespace {
Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) {
debug << "Key" << Debug::nospace;
switch(value) {
#define _c(value) case Application::KeyEvent::Key::value: return debug << "::" #value;
_c(Unknown)
_c(LeftShift)
_c(RightShift)
_c(LeftCtrl)
_c(RightCtrl)
_c(LeftAlt)
_c(RightAlt)
_c(LeftSuper)
_c(RightSuper)
_c(Enter)
_c(Esc)
_c(Up)
_c(Down)
_c(Left)
_c(Right)
_c(Home)
_c(End)
_c(PageUp)
_c(PageDown)
_c(Backspace)
_c(Insert)
_c(Delete)
_c(F1)
_c(F2)
_c(F3)
_c(F4)
_c(F5)
_c(F6)
_c(F7)
_c(F8)
_c(F9)
_c(F10)
_c(F11)
_c(F12)
_c(Space)
_c(Tab)
_c(Quote)
_c(Comma)
_c(Period)
_c(Minus)
_c(Plus)
_c(Slash)
_c(Percent)
_c(Semicolon)
_c(Equal)
_c(LeftBracket)
_c(RightBracket)
_c(Backslash)
_c(Backquote)
_c(World1)
_c(World2)
_c(Zero)
_c(One)
_c(Two)
_c(Three)
_c(Four)
_c(Five)
_c(Six)
_c(Seven)
_c(Eight)
_c(Nine)
_c(A)
_c(B)
_c(C)
_c(D)
_c(E)
_c(F)
_c(G)
_c(H)
_c(I)
_c(J)
_c(K)
_c(L)
_c(M)
_c(N)
_c(O)
_c(P)
_c(Q)
_c(R)
_c(S)
_c(T)
_c(U)
_c(V)
_c(W)
_c(X)
_c(Y)
_c(Z)
_c(CapsLock)
_c(ScrollLock)
_c(NumLock)
_c(PrintScreen)
_c(Pause)
_c(Menu)
_c(NumZero)
_c(NumOne)
_c(NumTwo)
_c(NumThree)
_c(NumFour)
_c(NumFive)
_c(NumSix)
_c(NumSeven)
_c(NumEight)
_c(NumNine)
_c(NumDecimal)
_c(NumDivide)
_c(NumMultiply)
_c(NumSubtract)
_c(NumAdd)
_c(NumEnter)
_c(NumEqual)
#undef _c
}
return debug << "(" << Debug::nospace << UnsignedInt(value) << Debug::nospace << ")";
}
using namespace Containers::Literals; using namespace Containers::Literals;
struct GlfwApplicationTest: Platform::Application { struct GlfwApplicationTest: Platform::Application {
@ -61,9 +182,11 @@ struct GlfwApplicationTest: Platform::Application {
} }
void keyPressEvent(KeyEvent& event) override { void keyPressEvent(KeyEvent& event) override {
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 Debug{} << "key press event:" << event.key() << int(event.key())
Debug{} << "key press event:" << int(event.key()) << event.keyName(); #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302
#endif << event.keyName()
#endif
;
if(event.key() == KeyEvent::Key::F1) { if(event.key() == KeyEvent::Key::F1) {
Debug{} << "starting text input"; Debug{} << "starting text input";
@ -97,9 +220,11 @@ struct GlfwApplicationTest: Platform::Application {
} }
void keyReleaseEvent(KeyEvent& event) override { void keyReleaseEvent(KeyEvent& event) override {
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 Debug{} << "key release event:" << event.key() << int(event.key())
Debug{} << "key release event:" << int(event.key()) << event.keyName(); #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302
#endif << event.keyName()
#endif
;
} }
void mouseMoveEvent(MouseMoveEvent& event) override { void mouseMoveEvent(MouseMoveEvent& event) override {

132
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -52,6 +52,126 @@
namespace Magnum { namespace Platform { namespace Test { namespace { namespace Magnum { namespace Platform { namespace Test { namespace {
Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) {
debug << "Key" << Debug::nospace;
switch(value) {
#define _c(value) case Application::KeyEvent::Key::value: return debug << "::" #value;
_c(Unknown)
_c(LeftShift)
_c(RightShift)
_c(LeftCtrl)
_c(RightCtrl)
_c(LeftAlt)
_c(RightAlt)
_c(LeftSuper)
_c(RightSuper)
_c(AltGr)
_c(Enter)
_c(Esc)
_c(Up)
_c(Down)
_c(Left)
_c(Right)
_c(Home)
_c(End)
_c(PageUp)
_c(PageDown)
_c(Backspace)
_c(Insert)
_c(Delete)
_c(F1)
_c(F2)
_c(F3)
_c(F4)
_c(F5)
_c(F6)
_c(F7)
_c(F8)
_c(F9)
_c(F10)
_c(F11)
_c(F12)
_c(Space)
_c(Tab)
_c(Quote)
_c(Comma)
_c(Period)
_c(Minus)
_c(Plus)
_c(Slash)
_c(Percent)
_c(Semicolon)
_c(Equal)
_c(LeftBracket)
_c(RightBracket)
_c(Backslash)
_c(Backquote)
_c(Zero)
_c(One)
_c(Two)
_c(Three)
_c(Four)
_c(Five)
_c(Six)
_c(Seven)
_c(Eight)
_c(Nine)
_c(A)
_c(B)
_c(C)
_c(D)
_c(E)
_c(F)
_c(G)
_c(H)
_c(I)
_c(J)
_c(K)
_c(L)
_c(M)
_c(N)
_c(O)
_c(P)
_c(Q)
_c(R)
_c(S)
_c(T)
_c(U)
_c(V)
_c(W)
_c(X)
_c(Y)
_c(Z)
_c(CapsLock)
_c(ScrollLock)
_c(NumLock)
_c(PrintScreen)
_c(Pause)
_c(Menu)
_c(NumZero)
_c(NumOne)
_c(NumTwo)
_c(NumThree)
_c(NumFour)
_c(NumFive)
_c(NumSix)
_c(NumSeven)
_c(NumEight)
_c(NumNine)
_c(NumDecimal)
_c(NumDivide)
_c(NumMultiply)
_c(NumSubtract)
_c(NumAdd)
_c(NumEnter)
_c(NumEqual)
#undef _c
}
return debug << "(" << Debug::nospace << UnsignedInt(value) << Debug::nospace << ")";
}
using namespace Containers::Literals; using namespace Containers::Literals;
struct Sdl2ApplicationTest: Platform::Application { struct Sdl2ApplicationTest: Platform::Application {
@ -98,7 +218,11 @@ struct Sdl2ApplicationTest: Platform::Application {
} }
void keyPressEvent(KeyEvent& event) override { void keyPressEvent(KeyEvent& event) override {
Debug{} << "key press event:" << SDL_Keycode(event.key()) << event.keyName(); Debug{} << "key press event:" << event.key() << "keycode:" << SDL_Keycode(event.key()) << event.keyName() << "scancode:" << event.event().key.keysym.scancode
#ifndef CORRADE_TARGET_EMSCRIPTEN
<< SDL_GetScancodeName(event.event().key.keysym.scancode)
#endif
;
if(event.key() == KeyEvent::Key::F1) { if(event.key() == KeyEvent::Key::F1) {
Debug{} << "starting text input"; Debug{} << "starting text input";
@ -147,7 +271,11 @@ struct Sdl2ApplicationTest: Platform::Application {
} }
void keyReleaseEvent(KeyEvent& event) override { void keyReleaseEvent(KeyEvent& event) override {
Debug{} << "key release event:" << SDL_Keycode(event.key()) << event.keyName(); Debug{} << "key release event:" << event.key() << "keycode:" << SDL_Keycode(event.key()) << event.keyName() << "scancode:" << event.event().key.keysym.scancode
#ifndef CORRADE_TARGET_EMSCRIPTEN
<< SDL_GetScancodeName(event.event().key.keysym.scancode)
#endif
;
/* With EmscriptenApplication, this makes the event stop from /* With EmscriptenApplication, this makes the event stop from
propagating further to the page (such as when pressing F1). propagating further to the page (such as when pressing F1).

Loading…
Cancel
Save