org.lwjgl.glfw.GLFW.glfwGetKeyName()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(205)

本文整理了Java中org.lwjgl.glfw.GLFW.glfwGetKeyName()方法的一些代码示例,展示了GLFW.glfwGetKeyName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GLFW.glfwGetKeyName()方法的具体详情如下:
包路径:org.lwjgl.glfw.GLFW
类名称:GLFW
方法名:glfwGetKeyName

GLFW.glfwGetKeyName介绍

[英]Returns the layout-specific name of the specified printable key.

This function returns the name of the specified printable key, encoded as UTF-8. This is typically the character that key would produce without any modifier keys, intended for displaying key bindings to the user. For dead keys, it is typically the diacritic it would add to a character.

Do not use this function for text input. You will break text input for many languages even if it happens to work for yours.

If the key is #GLFW_KEY_UNKNOWN, the scancode is used to identify the key, otherwise the scancode is ignored. If you specify a non-printable key, or #GLFW_KEY_UNKNOWN and a scancode that maps to a non-printable key, this function returns NULL but does not emit an error.

This behavior allows you to always pass in the arguments in the key callback without modification.

The printable keys are:

  • #GLFW_KEY_APOSTROPHE
  • #GLFW_KEY_COMMA
  • #GLFW_KEY_MINUS
  • #GLFW_KEY_PERIOD
  • #GLFW_KEY_SLASH
  • #GLFW_KEY_SEMICOLON
  • #GLFW_KEY_EQUAL
  • #GLFW_KEY_LEFT_BRACKET
  • #GLFW_KEY_RIGHT_BRACKET
  • #GLFW_KEY_BACKSLASH
  • #GLFW_KEY_WORLD_1
  • #GLFW_KEY_WORLD_2
  • #GLFW_KEY_0 to #GLFW_KEY_9
  • #GLFW_KEY_A to #GLFW_KEY_Z
  • #GLFW_KEY_KP_0 to #GLFW_KEY_KP_9
  • #GLFW_KEY_KP_DECIMAL
  • #GLFW_KEY_KP_DIVIDE
  • #GLFW_KEY_KP_MULTIPLY
  • #GLFW_KEY_KP_SUBTRACT
  • #GLFW_KEY_KP_ADD
  • #GLFW_KEY_KP_EQUAL

Names for printable keys depend on keyboard layout, while names for non-printable keys are the same across layouts but depend on the application language and should be localized along with other user interface text.

The returned string is allocated and freed by GLFW. You should not free it yourself. It is valid until the next call to #glfwGetKeyName, or until the library is terminated.

This function must only be called from the main thread.
[中]返回指定可打印键的布局特定名称。
此函数返回指定的可打印密钥的名称,编码为UTF-8。这通常是key在没有任何修改键的情况下生成的字符,用于向用户显示键绑定。对于死键,它通常是它将添加到字符的变音符号。
请勿将此功能用于文本输入。您将中断多种语言的文本输入,即使它恰好适用于您的语言。
如果钥匙为#GLFW_key_UNKNOWN,则扫描码用于识别钥匙,否则将忽略扫描码。如果指定不可打印的密钥或#GLFW_key_UNKNOWN以及映射到不可打印密钥的扫描码,此函数将返回NULL,但不会发出错误。
此行为允许您始终在键回调中传递参数,而无需修改。
可打印的密钥是:
*#GLFW_KEY#u撇号
*#GLFW_键#逗号
*#GLFW_键#减号
*#GLFW_关键时期
*#GLFW_键#斜杠
*#GLFW_KEY_分号
*#GLFW_键_相等
*#GLFW_键(左)括号
*#GLFW_键_右_支架
*#GLFW_键#反斜杠
*#GLFW_KEY_WORLD_1
*#GLFW_KEY_WORLD_2
*#GLFW_键0至#GLFW_键9
*#GLFW_KEY_A至#GLFW_KEY_Z
*#GLFW_KEY_KP_0至#GLFW_KEY_KP_9
*#GLFW_键_KP_十进制
*#GLFW_KEY_KP_DIVIDE
*#GLFW_键_KP_乘法
*#GLFW_键_KP_减法
*#GLFW_键_KP_添加
*#GLFW_KEY_KP_EQUAL
可打印键的名称取决于键盘布局,而不可打印键的名称在布局中是相同的,但取决于应用程序语言,应与其他用户界面文本一起本地化。
返回的字符串由GLFW分配和释放。你不应该自己把它放出来。在下一次调用#glfwGetKeyName或库终止之前,它一直有效。
只能从主线程调用此函数。

代码示例

代码示例来源:origin: jsettlers/settlers-remake

@Override
  public void invoke(long window, int key, int scancode, int action, int mods) {
    String name = GLFW.glfwGetKeyName(key, scancode);
    if(name == null) {
      name = keys.get(key);
    }
    if(action == GLFW.GLFW_PRESS) {
      startKeyEvent(name);
    } else if(action == GLFW.GLFW_RELEASE){
      endKeyEvent(name);
    }
  }
};

代码示例来源:origin: nifty-gui/nifty-gui

@Nonnull
private KeyboardInputEvent createKeyEvent(final int key, final int scancode, final int action, final int mods) {
 final boolean keyDown = action == GLFW_PRESS || action == GLFW_REPEAT;
 final boolean shiftDown = (mods & GLFW_MOD_SHIFT) != 0;
 final boolean ctrlDown = (mods & GLFW_MOD_CONTROL) != 0;
 final int niftyKeyCode = GlfwToNiftyKeyCodeConverter.convertToNiftyKeyCode(key);
 final String keyName = glfwGetKeyName (key, scancode);
 final char keyChar = (keyName != null && keyName.length() == 1) ? keyName.charAt(0) : Character.MIN_VALUE;
 return new KeyboardInputEvent(niftyKeyCode, keyChar, keyDown, shiftDown, ctrlDown);
}

相关文章

GLFW类方法