示例#1
0
void key_callback (GLFWwindow* window, int key, int scancode, int action,
	int mods) {
	printf ("key %i scancode %i action %i mods %i\n", key, scancode, action,
		mods);
	const char* str = glfwGetKeyName (key, scancode);
	printf ("glfw localised name: %s\n", str);
}
示例#2
0
文件: events.c 项目: sailfish009/glfw
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    Slot* slot = glfwGetWindowUserPointer(window);
    const char* name = glfwGetKeyName(key, scancode);

    if (name)
    {
        printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (%s) (with%s) was %s\n",
               counter++, slot->number, glfwGetTime(), key, scancode,
               get_key_name(key),
               name,
               get_mods_name(mods),
               get_action_name(action));
    }
    else
    {
        printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (with%s) was %s\n",
               counter++, slot->number, glfwGetTime(), key, scancode,
               get_key_name(key),
               get_mods_name(mods),
               get_action_name(action));
    }

    if (action != GLFW_PRESS)
        return;

    switch (key)
    {
        case GLFW_KEY_C:
        {
            slot->closeable = !slot->closeable;

            printf("(( closing %s ))\n", slot->closeable ? "enabled" : "disabled");
            break;
        }

        case GLFW_KEY_L:
        {
            const int state = glfwGetInputMode(window, GLFW_LOCK_KEY_MODS);
            glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, !state);

            printf("(( lock key mods %s ))\n", !state ? "enabled" : "disabled");
            break;
        }
    }
}
示例#3
0
文件: ctx.c 项目: cloudhead/px
const char *ctx_keyname(int key)
{
	switch (key) {
	case GLFW_KEY_SPACE:
		return "<space>";
	case GLFW_KEY_ENTER:
		return "<return>";
	case GLFW_KEY_LEFT:
		return "<left>";
	case GLFW_KEY_RIGHT:
		return "<right>";
	case GLFW_KEY_DOWN:
		return "<down>";
	case GLFW_KEY_UP:
		return "<up>";
	}
	return glfwGetKeyName(key, 0);
}
示例#4
0
 void _keypressCallback(int rawKey, int scanCode, int state, int mods) {
     if (!glfwGetWindowAttrib(this->_window, GLFW_FOCUSED) && !this->GetFullscreen()) {
         return;
     }
     
     std::string key = glfwGetKeyName(rawKey);
     
     if (rawKey == -1) { // On OSX -1 is the function key and should be ignored
         return;
     }
     
     Json::Value val(Json::objectValue);
     
     val["rawKey"] = rawKey;
     val["key"] = key;
     val["rawPress"] = state;
     val["state"] = glfwGetKeyStateName(state);
     val["shift"] = (mods & GLFW_MOD_SHIFT);
     
     GetEventsSingilton()->GetEvent("rawInput")->Emit(val);
 }
// human readable
std::string KeyKeyboardButton::nameEasy() const
{
// GLFW don't handle these properly!
    switch ( code_ )
    {
        case GLFW_KEY_SPACE:         return "Space";
        case GLFW_KEY_APOSTROPHE:    return "'";
        case GLFW_KEY_COMMA:         return ",";
        case GLFW_KEY_MINUS:         return "-";
        case GLFW_KEY_PERIOD:        return ".";
        case GLFW_KEY_SLASH:         return "/";
        case GLFW_KEY_SEMICOLON:     return ";";
        case GLFW_KEY_LEFT_BRACKET:  return "<";
        case GLFW_KEY_RIGHT_BRACKET: return ">";
        case GLFW_KEY_BACKSLASH:     return "\\";
        case GLFW_KEY_WORLD_1:       return "[World1]";
        case GLFW_KEY_WORLD_2:       return "[World2]";
        case GLFW_KEY_EQUAL         : return "=";
        case GLFW_KEY_ESCAPE        : return "Esc";
        case GLFW_KEY_ENTER         : return "Enter";
        case GLFW_KEY_TAB           : return "Tab";
        case GLFW_KEY_BACKSPACE     : return "Backspace";
        case GLFW_KEY_INSERT        : return "Ins";
        case GLFW_KEY_DELETE        : return "Del";
        case GLFW_KEY_RIGHT         : return "Right";
        case GLFW_KEY_LEFT          : return "Left";
        case GLFW_KEY_DOWN          : return "Down";
        case GLFW_KEY_UP            : return "Up";
        case GLFW_KEY_PAGE_UP       : return "PageUp";
        case GLFW_KEY_PAGE_DOWN     : return "PageDown";
        case GLFW_KEY_HOME          : return "Home";
        case GLFW_KEY_END           : return "End";
        case GLFW_KEY_CAPS_LOCK     : return "CapsLock";
        case GLFW_KEY_SCROLL_LOCK   : return "ScrollLock";
        case GLFW_KEY_NUM_LOCK      : return "NumLock";
        case GLFW_KEY_PRINT_SCREEN  : return "PrntScr";
        case GLFW_KEY_PAUSE         : return "Pause";
        case GLFW_KEY_F1            : return "F1";
        case GLFW_KEY_F2            : return "F2";
        case GLFW_KEY_F3            : return "F3";
        case GLFW_KEY_F4            : return "F4";
        case GLFW_KEY_F5            : return "F5";
        case GLFW_KEY_F6            : return "F6";
        case GLFW_KEY_F7            : return "F7";
        case GLFW_KEY_F8            : return "F8";
        case GLFW_KEY_F9            : return "F9";
        case GLFW_KEY_F10           : return "F10";
        case GLFW_KEY_F11           : return "F11";
        case GLFW_KEY_F12           : return "F12";
        //case GLFW_KEY_KP_DECIMAL    : return "KP ";
        //case GLFW_KEY_KP_DIVIDE     : return "";
        //case GLFW_KEY_KP_MULTIPLY   : return "";
        //case GLFW_KEY_KP_SUBTRACT   : return "";
        //case GLFW_KEY_KP_ADD        : return "";
        case GLFW_KEY_KP_ENTER      : return "KP Enter";
        //case GLFW_KEY_KP_EQUAL      : return "";
        case GLFW_KEY_LEFT_SHIFT    : return "Left Shift";
        case GLFW_KEY_LEFT_CONTROL  : return "Left Ctrl";
        case GLFW_KEY_LEFT_ALT      : return "Left Alt";
        case GLFW_KEY_LEFT_SUPER    : return "Left Super";
        case GLFW_KEY_RIGHT_SHIFT   : return "Right Shift";
        case GLFW_KEY_RIGHT_CONTROL : return "Right Ctrl";
        case GLFW_KEY_RIGHT_ALT     : return "Right Alt";
        case GLFW_KEY_RIGHT_SUPER   : return "Right Super";
        case GLFW_KEY_MENU          : return "Menu";
    }

    auto n = glfwGetKeyName( code_, 0 );
    return n == nullptr ? "(unknown keyboard button)" : std::string( n );

}
示例#6
0
 /**
  *  @brief  The getKeyName function returns the localized name of the specified printable key.
  *          This is intended for displaying key bindings to the user.
  *
  *  If the key is KEY_UNKNOWN, the scancode is used instead, otherwise the scancode is ignored.
  *  If a non-printable key or (if the key is KEY_UNKNOWN) a scancode that maps to a non-printable
  *  key is specified, this function returns an empty string.
  *
  *  @param k The key to query.
  *  @param s The scancode of the key to query.
  *  @return The localized name of the key.
  *  @note   This may only be called from the main thread.
  */
 std::string getKeyName(const KeyType k, const char32_t s)
 {
     return glfwGetKeyName(static_cast<KeyBaseType>(k), static_cast<int>(s));
 }