Added scancode to key callback.
This commit is contained in:
parent
362bf5de64
commit
11615fcaf2
@ -311,6 +311,7 @@ GLFW.
|
||||
* Added `GLFW_VISIBLE` window hint and parameter for controlling and polling
|
||||
window visibility
|
||||
* Added `GLFW_REPEAT` key action for repeated keys
|
||||
* Added scancode parameter to key callback
|
||||
* Added `refreshRate` member to `GLFWvidmode` struct
|
||||
* Added key modifier parameter to key and mouse button callbacks
|
||||
* Added `windows` simple multi-window test program
|
||||
|
@ -43,7 +43,7 @@
|
||||
void init( void );
|
||||
void display( void );
|
||||
void reshape( GLFWwindow* window, int w, int h );
|
||||
void key_callback( GLFWwindow* window, int key, int action, int mods );
|
||||
void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods );
|
||||
void DrawBoingBall( void );
|
||||
void BounceBall( double dt );
|
||||
void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
|
||||
@ -245,7 +245,7 @@ void reshape( GLFWwindow* window, int w, int h )
|
||||
0.0, -1.0, 0.0 ); /* up vector */
|
||||
}
|
||||
|
||||
void key_callback( GLFWwindow* window, int key, int action, int mods )
|
||||
void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods )
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
|
@ -211,7 +211,7 @@ static void animate(void)
|
||||
|
||||
|
||||
/* change view angle, exit upon ESC */
|
||||
void key( GLFWwindow* window, int k, int action, int mods )
|
||||
void key( GLFWwindow* window, int k, int s, int action, int mods )
|
||||
{
|
||||
if( action != GLFW_PRESS ) return;
|
||||
|
||||
|
@ -477,7 +477,7 @@ static void update_mesh(void)
|
||||
* GLFW callback functions
|
||||
*********************************************************************/
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
|
@ -434,7 +434,7 @@ static void mouseButtonFun(GLFWwindow* window, int button, int action, int mods)
|
||||
do_redraw = 1;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
|
@ -270,7 +270,7 @@ static void error_callback(int error, const char* description)
|
||||
// Handle key strokes
|
||||
//========================================================================
|
||||
|
||||
void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
@ -265,6 +265,9 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* The unknown key */
|
||||
#define GLFW_KEY_UNKNOWN -1
|
||||
|
||||
/* Printable keys */
|
||||
#define GLFW_KEY_SPACE 32
|
||||
#define GLFW_KEY_APOSTROPHE 39 /* ' */
|
||||
@ -744,6 +747,7 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,double,double);
|
||||
*
|
||||
* @param[in] window The window that received the event.
|
||||
* @param[in] key The [keyboard key](@ref keys) that was pressed or released.
|
||||
* @param[in] scancode The system-specific scancode of the key.
|
||||
* @param[in] action @ref GLFW_PRESS, @ref GLFW_RELEASE or @ref GLFW_REPEAT.
|
||||
* @param[in] mods Bit field describing which [modifier keys](@ref mods) were
|
||||
* held down.
|
||||
@ -752,7 +756,7 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,double,double);
|
||||
*
|
||||
* @ingroup input
|
||||
*/
|
||||
typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int);
|
||||
typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int);
|
||||
|
||||
/*! @brief The function signature for Unicode character callbacks.
|
||||
*
|
||||
@ -1771,6 +1775,8 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value);
|
||||
* @param[in] key The desired [keyboard key](@ref keys).
|
||||
* @return One of `GLFW_PRESS` or `GLFW_RELEASE`.
|
||||
*
|
||||
* @note `GLFW_KEY_UNKNOWN` is not a valid key for this function.
|
||||
*
|
||||
* @ingroup input
|
||||
*/
|
||||
GLFWAPI int glfwGetKey(GLFWwindow* window, int key);
|
||||
@ -1857,6 +1863,14 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
|
||||
* focus, i.e. `GLFW_FOCUSED` will be false and the focus callback will have
|
||||
* already been called.
|
||||
*
|
||||
* The scancode of a key is specific to that platform or sometimes even to that
|
||||
* machine. Scancodes are intended to allow users to bind keys that don't have
|
||||
* a GLFW key token. Such keys have `key` set to `GLFW_KEY_UNKNOWN`, their
|
||||
* state is not saved and so it cannot be retrieved with @ref glfwGetKey.
|
||||
*
|
||||
* Sometimes GLFW needs to generate synthetic key events, in which case the
|
||||
* scancode may be zero.
|
||||
*
|
||||
* @param[in] window The window whose callback to set.
|
||||
* @param[in] cbfun The new key callback, or `NULL` to remove the currently
|
||||
* set callback.
|
||||
|
@ -203,9 +203,9 @@ static void centerCursor(_GLFWwindow *window)
|
||||
|
||||
@end
|
||||
|
||||
// Converts Mac OS X key modifiers into GLFW ones
|
||||
// Translates Mac OS X key modifiers into GLFW ones
|
||||
//
|
||||
static int convertKeyMods(NSUInteger flags)
|
||||
static int translateFlags(NSUInteger flags)
|
||||
{
|
||||
int mods = 0;
|
||||
|
||||
@ -221,9 +221,9 @@ static int convertKeyMods(NSUInteger flags)
|
||||
return mods;
|
||||
}
|
||||
|
||||
// Converts a Mac OS X keycode to a GLFW keycode
|
||||
// Translates a Mac OS X keycode to a GLFW keycode
|
||||
//
|
||||
static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
static int translateKey(unsigned int key)
|
||||
{
|
||||
// Keyboard symbol translation table
|
||||
// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
|
||||
@ -281,7 +281,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
/* 31 */ GLFW_KEY_SPACE,
|
||||
/* 32 */ GLFW_KEY_WORLD_1,
|
||||
/* 33 */ GLFW_KEY_BACKSPACE,
|
||||
/* 34 */ -1,
|
||||
/* 34 */ GLFW_KEY_UNKNOWN,
|
||||
/* 35 */ GLFW_KEY_ESCAPE,
|
||||
/* 36 */ GLFW_KEY_RIGHT_SUPER,
|
||||
/* 37 */ GLFW_KEY_LEFT_SUPER,
|
||||
@ -292,21 +292,21 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
/* 3c */ GLFW_KEY_RIGHT_SHIFT,
|
||||
/* 3d */ GLFW_KEY_RIGHT_ALT,
|
||||
/* 3e */ GLFW_KEY_RIGHT_CONTROL,
|
||||
/* 3f */ -1, /* Function */
|
||||
/* 3f */ GLFW_KEY_UNKNOWN, /* Function */
|
||||
/* 40 */ GLFW_KEY_F17,
|
||||
/* 41 */ GLFW_KEY_KP_DECIMAL,
|
||||
/* 42 */ -1,
|
||||
/* 42 */ GLFW_KEY_UNKNOWN,
|
||||
/* 43 */ GLFW_KEY_KP_MULTIPLY,
|
||||
/* 44 */ -1,
|
||||
/* 44 */ GLFW_KEY_UNKNOWN,
|
||||
/* 45 */ GLFW_KEY_KP_ADD,
|
||||
/* 46 */ -1,
|
||||
/* 46 */ GLFW_KEY_UNKNOWN,
|
||||
/* 47 */ GLFW_KEY_NUM_LOCK, /* Really KeypadClear... */
|
||||
/* 48 */ -1, /* VolumeUp */
|
||||
/* 49 */ -1, /* VolumeDown */
|
||||
/* 4a */ -1, /* Mute */
|
||||
/* 48 */ GLFW_KEY_UNKNOWN, /* VolumeUp */
|
||||
/* 49 */ GLFW_KEY_UNKNOWN, /* VolumeDown */
|
||||
/* 4a */ GLFW_KEY_UNKNOWN, /* Mute */
|
||||
/* 4b */ GLFW_KEY_KP_DIVIDE,
|
||||
/* 4c */ GLFW_KEY_KP_ENTER,
|
||||
/* 4d */ -1,
|
||||
/* 4d */ GLFW_KEY_UNKNOWN,
|
||||
/* 4e */ GLFW_KEY_KP_SUBTRACT,
|
||||
/* 4f */ GLFW_KEY_F18,
|
||||
/* 50 */ GLFW_KEY_F19,
|
||||
@ -322,26 +322,26 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
/* 5a */ GLFW_KEY_F20,
|
||||
/* 5b */ GLFW_KEY_KP_8,
|
||||
/* 5c */ GLFW_KEY_KP_9,
|
||||
/* 5d */ -1,
|
||||
/* 5e */ -1,
|
||||
/* 5f */ -1,
|
||||
/* 5d */ GLFW_KEY_UNKNOWN,
|
||||
/* 5e */ GLFW_KEY_UNKNOWN,
|
||||
/* 5f */ GLFW_KEY_UNKNOWN,
|
||||
/* 60 */ GLFW_KEY_F5,
|
||||
/* 61 */ GLFW_KEY_F6,
|
||||
/* 62 */ GLFW_KEY_F7,
|
||||
/* 63 */ GLFW_KEY_F3,
|
||||
/* 64 */ GLFW_KEY_F8,
|
||||
/* 65 */ GLFW_KEY_F9,
|
||||
/* 66 */ -1,
|
||||
/* 66 */ GLFW_KEY_UNKNOWN,
|
||||
/* 67 */ GLFW_KEY_F11,
|
||||
/* 68 */ -1,
|
||||
/* 68 */ GLFW_KEY_UNKNOWN,
|
||||
/* 69 */ GLFW_KEY_PRINT_SCREEN,
|
||||
/* 6a */ GLFW_KEY_F16,
|
||||
/* 6b */ GLFW_KEY_F14,
|
||||
/* 6c */ -1,
|
||||
/* 6c */ GLFW_KEY_UNKNOWN,
|
||||
/* 6d */ GLFW_KEY_F10,
|
||||
/* 6e */ -1,
|
||||
/* 6e */ GLFW_KEY_UNKNOWN,
|
||||
/* 6f */ GLFW_KEY_F12,
|
||||
/* 70 */ -1,
|
||||
/* 70 */ GLFW_KEY_UNKNOWN,
|
||||
/* 71 */ GLFW_KEY_F15,
|
||||
/* 72 */ GLFW_KEY_INSERT, /* Really Help... */
|
||||
/* 73 */ GLFW_KEY_HOME,
|
||||
@ -356,13 +356,13 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
/* 7c */ GLFW_KEY_RIGHT,
|
||||
/* 7d */ GLFW_KEY_DOWN,
|
||||
/* 7e */ GLFW_KEY_UP,
|
||||
/* 7f */ -1,
|
||||
/* 7f */ GLFW_KEY_UNKNOWN,
|
||||
};
|
||||
|
||||
if (macKeyCode >= 128)
|
||||
return -1;
|
||||
if (key >= 128)
|
||||
return GLFW_KEY_UNKNOWN;
|
||||
|
||||
return table[macKeyCode];
|
||||
return table[key];
|
||||
}
|
||||
|
||||
|
||||
@ -436,7 +436,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
_glfwInputMouseClick(window,
|
||||
GLFW_MOUSE_BUTTON_LEFT,
|
||||
GLFW_PRESS,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
translateFlags([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)mouseDragged:(NSEvent *)event
|
||||
@ -449,7 +449,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
_glfwInputMouseClick(window,
|
||||
GLFW_MOUSE_BUTTON_LEFT,
|
||||
GLFW_RELEASE,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
translateFlags([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)mouseMoved:(NSEvent *)event
|
||||
@ -470,7 +470,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
_glfwInputMouseClick(window,
|
||||
GLFW_MOUSE_BUTTON_RIGHT,
|
||||
GLFW_PRESS,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
translateFlags([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)rightMouseDragged:(NSEvent *)event
|
||||
@ -483,7 +483,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
_glfwInputMouseClick(window,
|
||||
GLFW_MOUSE_BUTTON_RIGHT,
|
||||
GLFW_RELEASE,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
translateFlags([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)otherMouseDown:(NSEvent *)event
|
||||
@ -491,7 +491,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
_glfwInputMouseClick(window,
|
||||
[event buttonNumber],
|
||||
GLFW_PRESS,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
translateFlags([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)otherMouseDragged:(NSEvent *)event
|
||||
@ -504,7 +504,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
_glfwInputMouseClick(window,
|
||||
[event buttonNumber],
|
||||
GLFW_RELEASE,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
translateFlags([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)mouseExited:(NSEvent *)event
|
||||
@ -548,14 +548,11 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)keyDown:(NSEvent *)event
|
||||
{
|
||||
const NSUInteger mods = [event modifierFlags];
|
||||
const int key = translateKey([event keyCode]);
|
||||
const int mods = translateFlags([event modifierFlags]);
|
||||
_glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods);
|
||||
|
||||
_glfwInputKey(window,
|
||||
convertMacKeyCode([event keyCode]),
|
||||
GLFW_PRESS,
|
||||
convertKeyMods(mods));
|
||||
|
||||
if ([event modifierFlags] & NSCommandKeyMask)
|
||||
if (mods & GLFW_MOD_SUPER)
|
||||
return;
|
||||
|
||||
NSString* characters = [event characters];
|
||||
@ -567,7 +564,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)flagsChanged:(NSEvent *)event
|
||||
{
|
||||
int action, key;
|
||||
int action;
|
||||
unsigned int newModifierFlags =
|
||||
[event modifierFlags] & NSDeviceIndependentModifierFlagsMask;
|
||||
|
||||
@ -578,17 +575,16 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
window->ns.modifierFlags = newModifierFlags;
|
||||
|
||||
key = convertMacKeyCode([event keyCode]);
|
||||
if (key != -1)
|
||||
_glfwInputKey(window, key, action, convertKeyMods([event modifierFlags]));
|
||||
const int key = translateKey([event keyCode]);
|
||||
const int mods = translateFlags([event modifierFlags]);
|
||||
_glfwInputKey(window, key, [event keyCode], action, mods);
|
||||
}
|
||||
|
||||
- (void)keyUp:(NSEvent *)event
|
||||
{
|
||||
_glfwInputKey(window,
|
||||
convertMacKeyCode([event keyCode]),
|
||||
GLFW_RELEASE,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
const int key = translateKey([event keyCode]);
|
||||
const int mods = translateFlags([event modifierFlags]);
|
||||
_glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods);
|
||||
}
|
||||
|
||||
- (void)scrollWheel:(NSEvent *)event
|
||||
|
10
src/input.c
10
src/input.c
@ -122,16 +122,15 @@ static void setStickyMouseButtons(_GLFWwindow* window, int enabled)
|
||||
////// GLFW event API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action, int mods)
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
GLboolean repeated = GL_FALSE;
|
||||
|
||||
if (key < 0 || key > GLFW_KEY_LAST)
|
||||
return;
|
||||
|
||||
if (action == GLFW_RELEASE && window->key[key] == GLFW_RELEASE)
|
||||
return;
|
||||
|
||||
if (key >= 0 && key <= GLFW_KEY_LAST)
|
||||
{
|
||||
if (action == GLFW_PRESS && window->key[key] == GLFW_PRESS)
|
||||
repeated = GL_TRUE;
|
||||
|
||||
@ -139,12 +138,13 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action, int mods)
|
||||
window->key[key] = _GLFW_STICK;
|
||||
else
|
||||
window->key[key] = (char) action;
|
||||
}
|
||||
|
||||
if (repeated)
|
||||
action = GLFW_REPEAT;
|
||||
|
||||
if (window->callbacks.key)
|
||||
window->callbacks.key((GLFWwindow*) window, key, action, mods);
|
||||
window->callbacks.key((GLFWwindow*) window, key, scancode, action, mods);
|
||||
}
|
||||
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int character)
|
||||
|
@ -606,11 +606,12 @@ void _glfwInputWindowCloseRequest(_GLFWwindow* window);
|
||||
/*! @brief Notifies shared code of a physical key event.
|
||||
* @param[in] window The window that received the event.
|
||||
* @param[in] key The key that was pressed or released.
|
||||
* @param[in] scancode The system-specific scan code of the key.
|
||||
* @param[in] action @ref GLFW_PRESS or @ref GLFW_RELEASE.
|
||||
* @param[in] mods The modifiers pressed when the event was generated.
|
||||
* @ingroup event
|
||||
*/
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action, int mods);
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
|
||||
/*! @brief Notifies shared code of a Unicode character input event.
|
||||
* @param[in] window The window that received the event.
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include <malloc.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#define _GLFW_KEY_INVALID -2
|
||||
|
||||
|
||||
// Updates the cursor clip rect
|
||||
//
|
||||
@ -214,7 +216,7 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// Next message is a RALT down message, which
|
||||
// means that this is not a proper LCTRL message
|
||||
return -1;
|
||||
return _GLFW_KEY_INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -360,8 +362,8 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
|
||||
default: break;
|
||||
}
|
||||
|
||||
// No matching translation was found, so return -1
|
||||
return -1;
|
||||
// No matching translation was found
|
||||
return GLFW_KEY_UNKNOWN;
|
||||
}
|
||||
|
||||
// Window callback function (handles window events)
|
||||
@ -471,7 +473,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
{
|
||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS, getKeyMods());
|
||||
const int scancode = (lParam >> 16) & 0xff;
|
||||
const int key = translateKey(wParam, lParam);
|
||||
if (key == _GLFW_KEY_INVALID)
|
||||
break;
|
||||
|
||||
_glfwInputKey(window, key, scancode, GLFW_PRESS, getKeyMods());
|
||||
break;
|
||||
}
|
||||
|
||||
@ -500,22 +507,26 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
case WM_SYSKEYUP:
|
||||
{
|
||||
const int mods = getKeyMods();
|
||||
const int scancode = (lParam >> 16) & 0xff;
|
||||
const int key = translateKey(wParam, lParam);
|
||||
if (key == _GLFW_KEY_INVALID)
|
||||
break;
|
||||
|
||||
if (wParam == VK_SHIFT)
|
||||
{
|
||||
// Release both Shift keys on Shift up event, as only one event
|
||||
// is sent even if both keys are released
|
||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods);
|
||||
}
|
||||
else if (wParam == VK_SNAPSHOT)
|
||||
{
|
||||
// Key down is not reported for the print screen key
|
||||
_glfwInputKey(window, GLFW_KEY_PRINT_SCREEN, GLFW_PRESS, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_PRINT_SCREEN, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, key, scancode, GLFW_PRESS, mods);
|
||||
_glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
|
||||
}
|
||||
else
|
||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE, getKeyMods());
|
||||
_glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -1064,10 +1075,10 @@ void _glfwPlatformPollEvents(void)
|
||||
// See if this differs from our belief of what has happened
|
||||
// (we only have to check for lost key up events)
|
||||
if (!lshiftDown && window->key[GLFW_KEY_LEFT_SHIFT] == 1)
|
||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, 0, GLFW_RELEASE, mods);
|
||||
|
||||
if (!rshiftDown && window->key[GLFW_KEY_RIGHT_SHIFT] == 1)
|
||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, 0, GLFW_RELEASE, mods);
|
||||
}
|
||||
|
||||
// Did the cursor move in an focused window that has captured the cursor
|
||||
|
@ -77,7 +77,7 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
|
||||
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
||||
{
|
||||
if (window->key[i] == GLFW_PRESS)
|
||||
_glfwInputKey(window, i, GLFW_RELEASE, 0);
|
||||
_glfwInputKey(window, i, 0, GLFW_RELEASE, 0);
|
||||
}
|
||||
|
||||
// Release all pressed mouse buttons
|
||||
|
@ -39,13 +39,13 @@
|
||||
|
||||
// Translate an X11 key code to a GLFW key code.
|
||||
//
|
||||
static int keyCodeToGLFWKeyCode(int keyCode)
|
||||
static int translateKey(int keyCode)
|
||||
{
|
||||
int keySym;
|
||||
|
||||
// Valid key code range is [8,255], according to the XLib manual
|
||||
if (keyCode < 8 || keyCode > 255)
|
||||
return -1;
|
||||
return GLFW_KEY_UNKNOWN;
|
||||
|
||||
// Try secondary keysym, for numeric keypad keys
|
||||
// Note: This way we always force "NumLock = ON", which is intentional
|
||||
@ -211,8 +211,8 @@ static int keyCodeToGLFWKeyCode(int keyCode)
|
||||
default: break;
|
||||
}
|
||||
|
||||
// No matching translation was found, so return -1
|
||||
return -1;
|
||||
// No matching translation was found
|
||||
return GLFW_KEY_UNKNOWN;
|
||||
}
|
||||
|
||||
// Update the key code LUT
|
||||
@ -225,7 +225,7 @@ static void updateKeyCodeLUT(void)
|
||||
|
||||
// Clear the LUT
|
||||
for (keyCode = 0; keyCode < 256; keyCode++)
|
||||
_glfw.x11.keyCodeLUT[keyCode] = -1;
|
||||
_glfw.x11.keyCodeLUT[keyCode] = GLFW_KEY_UNKNOWN;
|
||||
|
||||
// Use XKB to determine physical key locations independently of the current
|
||||
// keyboard layout
|
||||
@ -296,7 +296,7 @@ static void updateKeyCodeLUT(void)
|
||||
else if (strcmp(name, "AB10") == 0) keyCodeGLFW = GLFW_KEY_SLASH;
|
||||
else if (strcmp(name, "BKSL") == 0) keyCodeGLFW = GLFW_KEY_BACKSLASH;
|
||||
else if (strcmp(name, "LSGT") == 0) keyCodeGLFW = GLFW_KEY_WORLD_1;
|
||||
else keyCodeGLFW = -1;
|
||||
else keyCodeGLFW = GLFW_KEY_UNKNOWN;
|
||||
|
||||
// Update the key code LUT
|
||||
if ((keyCode >= 0) && (keyCode < 256))
|
||||
@ -311,7 +311,7 @@ static void updateKeyCodeLUT(void)
|
||||
for (keyCode = 0; keyCode < 256; keyCode++)
|
||||
{
|
||||
if (_glfw.x11.keyCodeLUT[keyCode] < 0)
|
||||
_glfw.x11.keyCodeLUT[keyCode] = keyCodeToGLFWKeyCode(keyCode);
|
||||
_glfw.x11.keyCodeLUT[keyCode] = translateKey(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,8 @@ static int translateKey(int keycode)
|
||||
// Use the pre-filled LUT (see updateKeyCodeLUT() in x11_init.c)
|
||||
if ((keycode >= 0) && (keycode < 256))
|
||||
return _glfw.x11.keyCodeLUT[keycode];
|
||||
else
|
||||
return -1;
|
||||
|
||||
return GLFW_KEY_UNKNOWN;
|
||||
}
|
||||
|
||||
// Translates an X Window event to Unicode
|
||||
@ -515,7 +515,7 @@ static void processEvent(XEvent *event)
|
||||
const int key = translateKey(event->xkey.keycode);
|
||||
const int mods = translateState(event->xkey.state);
|
||||
|
||||
_glfwInputKey(window, key, GLFW_PRESS, mods);
|
||||
_glfwInputKey(window, key, event->xkey.keycode, GLFW_PRESS, mods);
|
||||
|
||||
if (!(mods & GLFW_MOD_CONTROL) && !(mods & GLFW_MOD_ALT))
|
||||
_glfwInputChar(window, translateChar(&event->xkey));
|
||||
@ -528,7 +528,7 @@ static void processEvent(XEvent *event)
|
||||
const int key = translateKey(event->xkey.keycode);
|
||||
const int mods = translateState(event->xkey.state);
|
||||
|
||||
_glfwInputKey(window, key, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, key, event->xkey.keycode, GLFW_RELEASE, mods);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
||||
set_swap_interval(window, 1 - swap_interval);
|
||||
|
@ -44,7 +44,7 @@ static void error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
@ -172,6 +172,7 @@ static const char* get_key_name(int key)
|
||||
case GLFW_KEY_LEFT_SUPER: return "LEFT SUPER";
|
||||
case GLFW_KEY_RIGHT_SUPER: return "RIGHT SUPER";
|
||||
case GLFW_KEY_MENU: return "MENU";
|
||||
case GLFW_KEY_UNKNOWN: return "UNKNOWN";
|
||||
|
||||
default: return NULL;
|
||||
}
|
||||
@ -339,11 +340,12 @@ static void scroll_callback(GLFWwindow* window, double x, double y)
|
||||
printf("%08x at %0.3f: Scroll: %0.3f %0.3f\n", counter++, glfwGetTime(), x, y);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
const char* name = get_key_name(key);
|
||||
|
||||
printf("%08x at %0.3f: Key 0x%04x", counter++, glfwGetTime(), key);
|
||||
printf("%08x at %0.3f: Key 0x%04x Scancode 0x%04x",
|
||||
counter++, glfwGetTime(), key, scancode);
|
||||
|
||||
if (name)
|
||||
printf(" (%s)", name);
|
||||
|
@ -48,7 +48,7 @@ static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
@ -60,7 +60,7 @@ static void error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
@ -45,7 +45,7 @@ static void error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
printf("%0.2f Key %s\n",
|
||||
glfwGetTime(),
|
||||
|
@ -74,7 +74,7 @@ static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
|
@ -65,7 +65,7 @@ static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ static void window_close_callback(GLFWwindow* window)
|
||||
printf("Close callback triggered\n");
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
@ -44,7 +44,7 @@ static void error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
|
@ -64,7 +64,7 @@ static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
||||
set_swap_interval(window, 1 - swap_interval);
|
||||
|
Loading…
Reference in New Issue
Block a user