2

我目前正在使用gloss'编写游戏play。这个游戏的基本结构非常简单:我有一个带有单位的棋盘,其中一个是焦点。

我添加了通过使用KeyTab. 很快,我意识到我也希望能够循环回来,所以我想我会Shift + KeyTab按照这种情况下的习惯这样做。

gloss的附带,其中之一Event。完美的?嗯......不完全是:每当我按 时,窗口永远不会收到事件(我使用's打印所有收到的 s)。ModifiersshiftShift + KeyTabDebug.TracetraceEvent

使用 CAPS LOCK,我确实收到KeyTabshift标记为 的修饰符Down。如果我切换到使用Ctrl + KeyTab作为我的快捷方式,它工作得非常好。这是重现问题的最小示例:

module Main where

import Graphics.Gloss
import Graphics.Gloss.Interface.Pure.Game

data Board = Board Color Color Color

forward :: Board -> Board
forward (Board x y z) = Board y z x

backward :: Board -> Board
backward (Board x y z) = Board z x y

displayPoint :: Point -> Color -> Picture
displayPoint (x, y) c = translate x y $ color c $ circle 10

displayBoard :: Board -> Picture
displayBoard (Board x y z) =
  Pictures $ zipWith displayPoint coordinates [x, y, z]
  where coordinates = [(0, 30), (-30, -30), (30, -30)]

react :: Event -> Board -> Board
react (EventKey (SpecialKey KeyTab) Down mods _) b =
  case shift mods of
    Up   -> forward b
    Down -> backward b
react _ b = b

main :: IO ()
main =
  let window = InWindow "Buggy" (100, 100) (200, 200)
      board  = Board blue red yellow
  in play window black 24 board displayBoard react (const id)
4

0 回答 0