On Sun, 12 Sep 2010 06:11:09 +0200, Tom Ostojich <tostoj...@gmail.com>  
wrote:

> Hey all,
>
> Excuse me if I'm missing something obvious, since I'm new to both Haskell
> programming and even newer yet to GUI programming, but I'm not sure on  
> how
> to resolve this issue.
>
> Basically, I know that you can use the charKey function to determine  
> whether
> or not a character key is pressed, but there appears to be no standard
> library function for checking if a key and a modifier, such as the  
> Control
> or Meta keys, are pressed as well.
>
> Is there a way to get something so that, once a <modifier> + <character  
> key>
> combination is pressed to generate an appropriate event, so I can do  
> stuff
> with that combination?
>

Somehow, the code in my previous mail was mangled (probably because of the  
'>' at the start of the lines), so here is it again.



I used the following function to handle keystrokes without modifier keys:

handleKeyboard :: MainFrame -> Var GameState -> EventKey -> IO ()
handleKeyboard f game k =
   if noModifierKeyPressed
     then
       case keyKey k of
         KeyChar 'z' -> moveLeft  f game
         KeyChar 'c' -> moveRight f game
         KeyChar 's' -> moveUp    f game
         KeyChar 'x' -> moveDown  f game

         KeyLeft     -> moveLeft  f game
         KeyRight    -> moveRight f game
         KeyUp       -> moveUp    f game
         KeyDown     -> moveDown  f game

         _           -> propagateEvent

     else
       propagateEvent

     where
       noModifierKeyPressed = keyModifiers k == Modifiers False False False  
False


This handles keyboard events, see [0]; use the following to activate this:

     set f [ on keyboard := handleKeyboard f game ]

where f is the handle of frame.

Regards,
Henk-Jan van Tuyl


[0]  
http://hackage.haskell.org/packages/archive/wx/latest/doc/html/Graphics-UI-WX-Events.html


-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
wxhaskell-users mailing list
wxhaskell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to