Writing a program in Haskell, I am struggling to handle key presses of the form ctrl-s and ctrl-l
I am using the following code:
main :: IO ()
main = do
hSetBuffering stdin NoBuffering
x <- getChar
putStrLn ("You pressed: " ++ [x])
How can I make it recognise the Ctrl button being pressed?
getChar gives you access to characters, not keypresses. Which character you get depends on your user's operating system, keyboard layout, and choice of input method. There is no 'standard' Character which will be generated by the keypresses Ctrl-S or Ctrl-L (although, certainly, some systems will give the standard ASCII codes for those control characters, others will not).
If you want proper keypress handling you need a real input library - like, for example, SDL or WxWidgets or GTK; each of which is much more than just an input library but they do have keypress abstractions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With