我正在尝试编写一个小程序,使用Haskell SDL绑定来检测游戏控制器上的按钮输入。我的程序非常简单:
import Control.Monad (forever, when)
import System.Exit (exitSuccess)
import Data.Time.Clock.POSIX (getPOSIXTime)
import qualified Graphics.UI.SDL.General as SG
import qualified Graphics.UI.SDL.Events as SE
import qualified Graphics.UI.SDL.Joystick as SJ
import qualified Graphics.UI.SDL.Video as SV
import qualified Graphics.UI.SDL.Types as ST
main :: IO ()
main =
SG.withInit [SG.InitVideo, SG.InitJoystick] $ do
-- Open joystick. We assume it's always present.
numJoysticks <- SJ.countAvailable
putStrLn $ show numJoysticks ++ " joystick(s) available"
js <- SJ.open 0
-- Create window
SV.setVideoMode 320 240 24 [ST.SWSurface, ST.Resizable]
-- Handle events
forever $ do
evt <- SE.waitEvent
case evt of
SE.JoyButtonDown dev btn -> do
t <- getPOSIXTime
print (show t ++ " - Button pressed: " ++ show dev ++ " " ++ show btn)
SE.Quit -> exitSuccess
_ -> return ()
在我的系统上(Debian稳定版,GHC 7.4,libghc-sdl-dev 0.6.3),程序在执行的第一秒钟(左右)内捕获按钮事件,然后就没有反应了。我的代码有问题吗?
import qualified TheModule as SDL
导入,然后将它们的所有函数作为SDL.f
访问-您不会在SDL本身内部遇到任何命名空间冲突。 - Cubic