本文整理汇总了Golang中sdl.Event.Keyboard方法的典型用法代码示例。如果您正苦于以下问题:Golang Event.Keyboard方法的具体用法?Golang Event.Keyboard怎么用?Golang Event.Keyboard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sdl.Event
的用法示例。
在下文中一共展示了Event.Keyboard方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: eventLoop
func (win *window) eventLoop() {
if win.ec == nil {
win.ec = make(chan interface{})
}
eloop:
for win.events {
var ev sdl.Event
for ev.Poll() {
switch ev.Type {
case sdl.KEYUP:
key := ev.Keyboard().Keysym.Sym
win.ec <- gui.KeyEvent{int(-key)}
case sdl.KEYDOWN:
key := ev.Keyboard().Keysym.Sym
win.ec <- gui.KeyEvent{int(key)}
case sdl.MOUSEMOTION:
m := ev.MouseMotion()
win.ec <- gui.MouseEvent{
Buttons: int(m.State),
Loc: image.Pt(int(m.X), int(m.Y)),
Nsec: time.Nanoseconds(),
}
case sdl.MOUSEBUTTONUP, sdl.MOUSEBUTTONDOWN:
m := ev.MouseButton()
win.ec <- gui.MouseEvent{
Buttons: int(sdl.GetMouseState(nil, nil)),
Loc: image.Pt(int(m.X), int(m.Y)),
Nsec: time.Nanoseconds(),
}
case sdl.VIDEORESIZE:
r := ev.Resize()
win.ec <- gui.ConfigEvent{image.Config{
win.Screen().ColorModel(),
int(r.W),
int(r.H),
}}
case sdl.QUIT:
break eloop
}
}
}
close(win.ec)
}
示例2: sdlRenderLoop
func (engine *SDLEngine) sdlRenderLoop() {
runtime.LockOSThread()
for {
var event sdl.Event
for event.Poll() {
switch event.Type {
case sdl.MOUSEMOTION:
m := event.MouseMotion()
engine.mouseEventChan <- MouseEvent{int32(m.X), int32(m.Y), int32(m.Xrel), int32(m.Yrel), int32(m.State)}
case sdl.KEYDOWN, sdl.KEYUP:
k := event.Keyboard()
engine.keyEventChan <- KeyEvent{uint32(k.Keysym.Sym), uint32(k.Type)}
case sdl.QUIT:
engine.systemEventChan <- SystemEvent{SystemQuit}
return
}
}
engine.frameEventChan <- FrameEvent{0.0}
}
runtime.UnlockOSThread()
}