func (i *input) update(window *glfw.Window, scale int) error { for g, e := range glfwKeyCodeToKey { i.keyPressed[e] = window.GetKey(g) == glfw.Press } for g, e := range glfwMouseButtonToMouseButton { i.mouseButtonPressed[e] = window.GetMouseButton(g) == glfw.Press } x, y := window.GetCursorPos() i.cursorX = int(math.Floor(x)) / scale i.cursorY = int(math.Floor(y)) / scale for id := glfw.Joystick(0); id < glfw.Joystick(len(i.gamepads)); id++ { if !glfw.JoystickPresent(id) { continue } axes32 := glfw.GetJoystickAxes(id) i.gamepads[id].axisNum = len(axes32) for a := 0; a < len(i.gamepads[id].axes); a++ { if len(axes32) <= a { i.gamepads[id].axes[a] = 0 continue } i.gamepads[id].axes[a] = float64(axes32[a]) } buttons := glfw.GetJoystickButtons(id) i.gamepads[id].buttonNum = len(buttons) for b := 0; b < len(i.gamepads[id].buttonPressed); b++ { if len(buttons) <= b { i.gamepads[id].buttonPressed[b] = false continue } i.gamepads[id].buttonPressed[b] = glfw.Action(buttons[b]) == glfw.Press } } return nil }
func (c *chip8) setKeys(window *glfw.Window) { for k, v := range keyvalues { if window.GetKey(k) == glfw.Release { c.key[v] = true } else { c.key[v] = false } } }
func (c *chip8) Chip8_FX0A(window *glfw.Window) { //FX0A: A key press is awaited, and then stored in VX. glfw.WaitEvents() for k, v := range keyvalues { if window.GetKey(k) == glfw.Press { c.v[(c.opcode & 0x0F00) >> 8] = v c.key[v] = true c.pc += 2 break } } }
// inputUpdate handles input actions that are dependent on the delta between frames. // (e.g. how much you move depends on the time delta since the last update) func inputUpdate(w *glfw.Window, delta float32) { for key, cb := range activeKeyboard.keyBindings { if w.GetKey(key) == glfw.Press && cb != nil { cb(delta) } } // if the joystick is still connected, then we do the joystick polling // TODO: for now, we're just working with Joystick1 as hardcoded if glfw.JoystickPresent(glfw.Joystick1) { buttons := glfw.GetJoystickButtons(glfw.Joystick1) axes := glfw.GetJoystickAxes(glfw.Joystick1) //groggy.Logsf("DEBUG", "inputUpdate: %d %d %d %d %d %d %d %d %d %d %d %d %d %d ", buttons[0], buttons[1], buttons[2], buttons[3], buttons[4], // buttons[5], buttons[6], buttons[7], buttons[8], buttons[9], // buttons[10], buttons[11], buttons[12], buttons[13]) // process the buttons for buttonId, cb := range activeJoystick.buttonBindings { if buttons[buttonId] > 0 && cb != nil { cb(delta) } } // process the axis values for _, mapping := range activeJoystick.axisBindings { if mapping.Callback == nil { continue } v := axes[mapping.Id] if v >= mapping.Min && v <= mapping.Max { scale := mapping.Max - mapping.Min if mapping.NegativeMapping { // use the Max value here since NegativeMapping implies a negative ranage for the mapping v = (float32(math.Abs(float64(v))) - float32(math.Abs(float64(mapping.Max)))) / scale } else { v = (v - mapping.Min) / scale } mapping.Callback(delta * v) } } // axisBindings } }
func painalluksetOhjaimiksi(ikkuna *glfw.Window) (ohjaimet Ohjaimet) { ohjaimet.Kaasu = ikkuna.GetKey(glfw.KeyUp) == glfw.Press ohjaimet.Liipaisin = ikkuna.GetKey(glfw.KeySpace) == glfw.Press if ikkuna.GetKey(glfw.KeyLeft) == glfw.Press { ohjaimet.Ratti += 1 } if ikkuna.GetKey(glfw.KeyRight) == glfw.Press { ohjaimet.Ratti -= 1 } return }
func readKey(window *glfw.Window, key glfw.Key) bool { return window.GetKey(key) == glfw.Press }
func onKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) { // Debug override if key == glfw.KeyGraveAccent && action == glfw.Release { con.focus() return } if currentScreen != nil { ui.HandleKey(w, key, scancode, action, mods) return } if Client.chat.enteringText { Client.chat.handleKey(w, key, scancode, action, mods) return } if k, ok := keyStateMap[key]; action != glfw.Repeat && ok { Client.KeyState[k] = action == glfw.Press } switch key { case glfw.KeyEscape: if action == glfw.Release { setScreen(newGameMenu()) } case glfw.KeyF1: if action == glfw.Release { if Client.scene.IsVisible() { Client.scene.Hide() Client.hotbarScene.Hide() } else { Client.scene.Show() Client.hotbarScene.Show() } } case glfw.KeyF3: if action == glfw.Release { Client.toggleDebug() } case glfw.KeyF5: if action == glfw.Release { Client.cycleCamera() } case glfw.KeyTab: if action == glfw.Press { Client.playerList.set(true) } else if action == glfw.Release { Client.playerList.set(false) } case glfw.KeyE: if action == glfw.Release { wasPlayer := Client.activeInventory == Client.playerInventory closeInventory() if wasPlayer { return } openInventory(Client.playerInventory) } case glfw.KeyT: state := w.GetKey(glfw.KeyF3) if action == glfw.Release && state == glfw.Press { reloadResources() return } fallthrough case glfw.KeySlash: if action != glfw.Release { return } for i := range Client.KeyState { Client.KeyState[i] = false } Client.chat.enteringText = true if key == glfw.KeySlash { Client.chat.inputLine = append(Client.chat.inputLine, '/') } lockMouse = false w.SetInputMode(glfw.CursorMode, glfw.CursorNormal) w.SetCharCallback(Client.chat.handleChar) } }
func onKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) { // Debug override if key == glfw.KeyGraveAccent && action == glfw.Release { con.focus() return } if currentScreen != nil { ui.HandleKey(w, key, scancode, action, mods) return } if Client.chat.enteringText { Client.chat.handleKey(w, key, scancode, action, mods) return } // For creative flying if Client.GameMode.Fly() && keyStateMap[key] == KeyJump && action == glfw.Press { now := time.Now() if now.Sub(lastJumpPress) < 500*time.Millisecond { Client.isFlying = !Client.isFlying } lastJumpPress = now } if k, ok := keyStateMap[key]; action != glfw.Repeat && ok { Client.KeyState[k] = action == glfw.Press } if key >= glfw.Key0 && key <= glfw.Key9 && action == glfw.Press { slot := int((8 + (key - glfw.Key0)) % 9) Client.currentHotbarSlot = slot Client.network.Write(&protocol.HeldItemChange{Slot: int16(Client.currentHotbarSlot)}) } switch key { case glfw.KeyEscape: if action == glfw.Release { setScreen(newGameMenu()) } case glfw.KeyF1: if action == glfw.Release { if Client.scene.IsVisible() { Client.scene.Hide() Client.hotbarScene.Hide() } else { Client.scene.Show() Client.hotbarScene.Show() } } case glfw.KeyF3: if action == glfw.Release { Client.toggleDebug() } case glfw.KeyF5: if action == glfw.Release { Client.cycleCamera() } case glfw.KeyTab: if action == glfw.Press { Client.playerList.set(true) } else if action == glfw.Release { Client.playerList.set(false) } case glfw.KeyE: if action == glfw.Release { wasPlayer := Client.activeInventory == Client.playerInventory closeInventory() if wasPlayer { return } openInventory(Client.playerInventory) } case glfw.KeyT: state := w.GetKey(glfw.KeyF3) if action == glfw.Release && state == glfw.Press { reloadResources() return } fallthrough case glfw.KeySlash: if action != glfw.Release { return } for i := range Client.KeyState { Client.KeyState[i] = false } Client.chat.enteringText = true if key == glfw.KeySlash { Client.chat.inputLine = append(Client.chat.inputLine, '/') } lockMouse = false w.SetInputMode(glfw.CursorMode, glfw.CursorNormal) w.SetCharCallback(Client.chat.handleChar) } }