Skip to content

Commit 31a5909

Browse files
committed
Support capitals and some punctuation in uinput example
This is about as far as we should go, but it does make for a more useful demo. For anything much more complex, `evdev` isn't really the right tool for the job, since it lacks awareness of keyboard layouts etc. One should probably use something like `xdotool`/`ydotool`.
1 parent 7edab77 commit 31a5909

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

evdev-examples/uinput/Main.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Main (main) where
22

33
import Control.Exception
44
import Control.Monad
5+
import Data.Char
56
import Data.Maybe
67
import System.Exit
78
import System.IO.Error
@@ -14,14 +15,14 @@ main = do
1415
dev <-
1516
newDevice
1617
"haskell-uinput-echo-example"
17-
defaultDeviceOpts{keys = mapMaybe charToEvent (['a' .. 'z'] ++ ['0' .. '9'])}
18+
defaultDeviceOpts{keys = mapMaybe charToEvent (['a' .. 'z'] ++ ['0' .. '9'] ++ [' ', '.', ',', '\''])}
1819
forever do
1920
cs <-
2021
catchJust
2122
(guard . isEOFError)
2223
getLine
2324
\() -> exitSuccess
24-
writeBatch dev [KeyEvent k a | Just k <- map charToEvent cs, a <- [Pressed, Released]]
25+
writeBatch dev [KeyEvent k a | Just k <- map (charToEvent . toLower) cs, a <- [Pressed, Released]]
2526

2627
charToEvent :: Char -> Maybe Codes.Key
2728
charToEvent = \case
@@ -61,4 +62,8 @@ charToEvent = \case
6162
'x' -> Just Codes.KeyX
6263
'y' -> Just Codes.KeyY
6364
'z' -> Just Codes.KeyZ
65+
' ' -> Just Codes.KeySpace
66+
'.' -> Just Codes.KeyDot
67+
',' -> Just Codes.KeyApostrophe
68+
'\'' -> Just Codes.KeyApostrophe
6469
_ -> Nothing

0 commit comments

Comments
 (0)