Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Graphics.UI.WX
- import Data.IORef
- main :: IO ()
- main = start $ do
- f <- frame [text := "Type speed meter"]
- input <- textCtrl f []
- status <- statusField []
- set f [statusBar := [status]]
- t <- timer f [interval := 1000]
- tick <- newIORef (0 :: Int)
- lastPressed <- newIORef []
- pressed <- newIORef (0 :: Int)
- let doStuff = do
- modifyIORef tick (+1)
- return ()
- lastTick <- readIORef tick
- modifyIORef lastPressed $ filter (> (lastTick - 15))
- currRate <- fmap ((*4) .length) $ readIORef lastPressed
- overallRate <- fmap ((`div` lastTick) . (*60)) $ readIORef pressed
- set status [text := "Current: " ++ show currRate ++ " Overall: " ++ show overallRate]
- let onKeyPress = do
- modifyIORef pressed (+1)
- lastTick <- readIORef tick
- modifyIORef lastPressed (lastTick : )
- propagateEvent
- set t [on command := doStuff]
- set input [on anyKey := const onKeyPress]
- return ()
Advertisement
Add Comment
Please, Sign In to add comment