本文整理汇总了Golang中github.com/go-gl/glfw/v3/1/glfw.Window.SetCharCallback方法的典型用法代码示例。如果您正苦于以下问题:Golang Window.SetCharCallback方法的具体用法?Golang Window.SetCharCallback怎么用?Golang Window.SetCharCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/go-gl/glfw/v3/1/glfw.Window
的用法示例。
在下文中一共展示了Window.SetCharCallback方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleKey
func (c *ChatUI) handleKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
if (key == glfw.KeyEscape || key == glfw.KeyEnter) && action == glfw.Release {
if key == glfw.KeyEnter && len(c.inputLine) != 0 {
Client.network.Write(&protocol.ChatMessage{string(c.inputLine)})
}
// Return control back to the default
c.enteringText = false
c.inputLine = c.inputLine[:0]
lockMouse = true
w.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
w.SetCharCallback(nil)
return
}
if key == glfw.KeyBackspace && action != glfw.Release {
if len(c.inputLine) > 0 {
c.inputLine = c.inputLine[:len(c.inputLine)-1]
}
}
}
示例2: onKey
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)
}
}
示例3: onKey
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)
}
}