From: Tom O. <tos...@gm...> - 2010-09-13 04:35:54
|
Hi Henk-Jan, Thanks for the snippet of code you submitted; it did the main part right, which was identifying whether or not a modifier and a key was pressed. However, and I'm not sure what the source of this problem is, whenever I use the constructor (KeyChar c), where c is a character, I don't get a value of type Key that represents the key at character c. To make this problem more concrete, I have submitted the following sample application which can be ran and tested to demonstrate what I mean: module Main where import Graphics.UI.WX import Graphics.UI.WXCore handleKeyboard :: Frame a -> EventKey -> IO() handleKeyboard f k = if controlKeyPressed then keyTestModifiers f (ks) else infoDialog f "info" "No ctrl-<key> combo activated" where controlKeyPressed = keyModifiers k == Modifiers False False True False ks = keyKey k keyTestModifiers :: Frame a -> Key -> IO() keyTestModifiers f k | k == (KeyChar 't') = infoDialog f "info" "Test: Ctrl-t activated" | k == (KeyReturn) = infoDialog f "info" "Test: Ctrl-Enter activated" | otherwise = infoDialog f "info" "Test: Different key activated" main :: IO () main = start gui gui :: IO () gui = do f <- frameFixed [text := "test"] p <- panel f [] set p [on keyboard := handleKeyboard f] Notice that if you compile and run this application and hit n, where n is any keyboard value, you get the expected response (A dialog saying "No Ctrl-key combo activated" pops up). Likewise, if you hit Ctrl-Enter, you get the expected response ("Test: Ctrl-Enter activated"). However, when you enter Ctrl-t, even though Ctrl-t should be defined, it returns "Test: Different Key Activated" instead of "Test: Ctrl-t activated"! I'm not sure why does it do this, but judging by the code snippet you presented, this shouldn't be expected behaviour. Regards, Tom Ostojich |