-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboardHandler.hs
23 lines (21 loc) · 1.01 KB
/
keyboardHandler.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module KeyboardHandler where
import Control.Concurrent.STM (TVar, atomically, modifyTVar)
import Graphics.UI.GLUT (KeyboardMouseCallback, Key(..), SpecialKey(..), KeyState(..), Modifiers(..), Position(..), fullScreenToggle)
import System.Exit (exitSuccess)
keyboardHandler :: TVar [Key] -> KeyboardMouseCallback
keyboardHandler _ (SpecialKey KeyF4) Down (Modifiers _ _ Down) _ = exitSuccess
keyboardHandler _ (SpecialKey KeyF11) Down _ _ = fullScreenToggle
keyboardHandler queue key Down _ _
| key `elem` validKeys = addToQueue
| otherwise = return ()
where validKeys = [ Char '\r'
, Char '\n'
, Char '\ESC'
, Char ' '
, SpecialKey KeyLeft
, SpecialKey KeyRight
, SpecialKey KeyUp
, SpecialKey KeyDown
, SpecialKey KeyShiftR ]
addToQueue = atomically $ modifyTVar queue (\q -> key:q)
keyboardHandler _ _ _ _ _ = return ()