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

x33g5p2x  于2022-01-19 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(231)

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

GLFW.glfwSetKeyCallback介绍

[英]Sets the key callback of the specified window, which is called when a key is pressed, repeated or released.

The key functions deal with physical keys, with layout independent key tokens named after their values in the standard US keyboard layout. If you want to input text, use #glfwSetCharCallback instead.

When a window loses input focus, it will generate synthetic key release events for all pressed keys. You can tell these events from user-generated events by the fact that the synthetic ones are generated after the focus loss event has been processed, i.e. after the window focus callback has 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 queried with #glfwGetKey.

Sometimes GLFW needs to generate synthetic key events, in which case the scancode may be zero.

This function must only be called from the main thread.
[中]设置指定窗口的键回调,在按下、重复或释放键时调用该窗口。
键函数处理物理键,与布局无关的键标记以其在标准美国键盘布局中的值命名。如果要输入文本,请改用#glfwSetCharCallback。
当窗口失去输入焦点时,它将为所有按下的键生成合成键释放事件。您可以通过以下事实来区分这些事件与用户生成的事件:合成事件是在处理焦点丢失事件之后生成的,即在调用窗口焦点回调之后生成的。
钥匙的扫描码特定于该平台,有时甚至特定于该机器。扫描码旨在允许用户绑定没有GLFW密钥令牌的密钥。此类密钥的密钥设置为#GLFW_key_UNKNOWN,其状态未保存,因此无法使用#glfwGetKey查询。
有时GLFW需要生成合成密钥事件,在这种情况下,扫描码可能为零。
只能从主线程调用此函数。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void initialize() {
  if (!context.isRenderable()) {
    return;
  }
  glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() {
    @Override
    public void invoke(long window, int key, int scancode, int action, int mods) {
      scancode = GlfwKeyMap.toJmeKeyCode(key);
      if( key == GLFW_KEY_LEFT_SHIFT || key == GLFW_KEY_RIGHT_SHIFT ) {
        shift_pressed = (action == GLFW_PRESS);
      } else if( key >= 'A' && key <= 'Z' && !shift_pressed ) {
        key += 32; // make lowercase
      } else if( key >= 'a' && key <= 'z' && shift_pressed ) {
        key -= 32; // make uppercase
      }
      final KeyInputEvent evt = new KeyInputEvent(scancode, (char) key, GLFW_PRESS == action, GLFW_REPEAT == action);
      evt.setTime(getInputTimeNanos());
      keyInputEvents.add(evt);
    }
  });
  glfwSetInputMode(context.getWindowHandle(), GLFW_STICKY_KEYS, 1);
  initialized = true;
  logger.fine("Keyboard created.");
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() {
  @Override
  public void invoke(final long window, final int key, final int scancode, final int action, final int mods) {

代码示例来源:origin: libgdx/libgdx

public void windowHandleChanged(long windowHandle) {
  resetPollingStates();
  GLFW.glfwSetKeyCallback(window.getWindowHandle(), keyCallback);
  GLFW.glfwSetCharCallback(window.getWindowHandle(), charCallback);
  GLFW.glfwSetScrollCallback(window.getWindowHandle(), scrollCallback);
  GLFW.glfwSetCursorPosCallback(window.getWindowHandle(), cursorPosCallback);
  GLFW.glfwSetMouseButtonCallback(window.getWindowHandle(), mouseButtonCallback);
}

代码示例来源:origin: libgdx/libgdx

public void windowHandleChanged(long windowHandle) {
  resetPollingStates();
  GLFW.glfwSetKeyCallback(window.getWindowHandle(), keyCallback);
  GLFW.glfwSetCharCallback(window.getWindowHandle(), charCallback);
  GLFW.glfwSetScrollCallback(window.getWindowHandle(), scrollCallback);
  GLFW.glfwSetCursorPosCallback(window.getWindowHandle(), cursorPosCallback);
  GLFW.glfwSetMouseButtonCallback(window.getWindowHandle(), mouseButtonCallback);
}

代码示例来源:origin: org.lwjgl.osgi/org.lwjgl.glfw

/** See {@link GLFW#glfwSetKeyCallback SetKeyCallback}. */
public GLFWKeyCallback set(long window) {
  glfwSetKeyCallback(window, this);
  return this;
}

代码示例来源:origin: Renanse/Ardor3D

@Override
public void init() {
  GLFW.glfwSetKeyCallback(_canvas.getWindowId(), (_keyCallback = new GLFWKeyCallback() {
    @Override
    public void invoke(final long window, final int keyCode, final int scancode, final int action,
        final int mods) {
      final Key key = GLFWKey.findByCode(keyCode);
      final KeyState state;
      switch (action) {
        case GLFW.GLFW_PRESS:
          state = KeyState.DOWN;
          break;
        case GLFW.GLFW_RELEASE:
          state = KeyState.UP;
          break;
        case GLFW.GLFW_REPEAT:
        default:
          // do nothing on REPEAT?
          return;
      }
      // TODO: Need to rewrite Ardor's text processing to handle text input coming from elsewhere.
      final char keyChar = '?';
      _upcomingEvents.add(new KeyEvent(key, state, keyChar));
    }
  }));
}

代码示例来源:origin: playn/playn

public GLFWInput(LWJGLPlatform plat, long window) {
 super(plat);
 this.plat = plat;
 this.window = window;
 glfwSetCharCallback(window, charCallback);
 glfwSetKeyCallback(window, keyCallback);
 glfwSetMouseButtonCallback(window, mouseBtnCallback);
 glfwSetCursorPosCallback(window, cursorPosCallback);
 glfwSetScrollCallback(window, scrollCallback);
}

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

private void registerCallbacks() {
    GLFW.glfwSetKeyCallback(glfw_wnd, key_callback);
    GLFW.glfwSetMouseButtonCallback(glfw_wnd, mouse_callback);
    GLFW.glfwSetScrollCallback(glfw_wnd, scroll_callback);
    GLFW.glfwSetCursorEnterCallback(glfw_wnd, cursorenter_callback);
    GLFW.glfwSetCursorPosCallback(glfw_wnd, cursorpos_callback);
    GLFW.glfwSetWindowSizeCallback(glfw_wnd, size_callback);
  }
}

代码示例来源:origin: com.badlogicgames.gdx/gdx-backend-lwjgl3

public void windowHandleChanged(long windowHandle) {
  resetPollingStates();
  GLFW.glfwSetKeyCallback(window.getWindowHandle(), keyCallback);
  GLFW.glfwSetCharCallback(window.getWindowHandle(), charCallback);
  GLFW.glfwSetScrollCallback(window.getWindowHandle(), scrollCallback);
  GLFW.glfwSetCursorPosCallback(window.getWindowHandle(), cursorPosCallback);
  GLFW.glfwSetMouseButtonCallback(window.getWindowHandle(), mouseButtonCallback);
}

代码示例来源:origin: badlogic/lwjgl3-maven-gradle

glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
  @Override
  public void invoke(long window, int key, int scancode, int action, int mods) {

代码示例来源:origin: badlogic/lwjgl3-maven-gradle

glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
  @Override
  public void invoke(long window, int key, int scancode, int action, int mods) {

代码示例来源:origin: lwjglgamedev/lwjglbook

glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
  if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
    glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

代码示例来源:origin: lwjglgamedev/lwjglbook

glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
  if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
    glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

代码示例来源:origin: lwjglgamedev/lwjglbook

glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
  if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
    glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

代码示例来源:origin: lwjglgamedev/lwjglbook

glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
  if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
    glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

代码示例来源:origin: lwjglgamedev/lwjglbook

glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
  if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
    glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

代码示例来源:origin: lwjglgamedev/lwjglbook

glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
  if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
    glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

代码示例来源:origin: lwjglgamedev/lwjglbook

glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
  if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
    glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

代码示例来源:origin: lwjglgamedev/lwjglbook

glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
  if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
    glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

代码示例来源:origin: SpinyOwl/legui

/**
 * Used to bind callbacks to OpenGL window. This method could be called only from main thread (Main OpenGL thread).
 *
 * @param window window to bind.
 * @param keeper callback keeper with callbacks.
 */
static void registerCallbacks(long window, CallbackKeeper keeper) {
  glfwSetCharCallback(window, keeper.getChainCharCallback());
  glfwSetDropCallback(window, keeper.getChainDropCallback());
  glfwSetKeyCallback(window, keeper.getChainKeyCallback());
  glfwSetScrollCallback(window, keeper.getChainScrollCallback());
  glfwSetCharModsCallback(window, keeper.getChainCharModsCallback());
  glfwSetCursorEnterCallback(window, keeper.getChainCursorEnterCallback());
  glfwSetFramebufferSizeCallback(window, keeper.getChainFramebufferSizeCallback());
  glfwSetMouseButtonCallback(window, keeper.getChainMouseButtonCallback());
  glfwSetCursorPosCallback(window, keeper.getChainCursorPosCallback());
  glfwSetWindowCloseCallback(window, keeper.getChainWindowCloseCallback());
  glfwSetWindowFocusCallback(window, keeper.getChainWindowFocusCallback());
  glfwSetWindowIconifyCallback(window, keeper.getChainWindowIconifyCallback());
  glfwSetWindowPosCallback(window, keeper.getChainWindowPosCallback());
  glfwSetWindowRefreshCallback(window, keeper.getChainWindowRefreshCallback());
  glfwSetWindowSizeCallback(window, keeper.getChainWindowSizeCallback());
}

相关文章

GLFW类方法