From 9e90fe70e8946749cfebb788ae709a90224b6c05 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Sun, 5 Jan 2025 15:33:24 +0100 Subject: [PATCH] Fix `uinput-echo` example In the setup of the device, the keys were initialized to ``` [Codes.KeyA .. Codes.KeyZ] ++ [Codes.Key1 .. Codes.Key0] ``` But that is incorrect: `KeyA` corresponds to value 30 and `KeyZ` corresponds to value 44; this therefore excludes keys such as `KeyB` (48) and others. This can be observed by running the example and typing `abcde`; only `ad` will be echoed back. Perhaps the better fix would be to modify the `Enum` instance, but that might result in difficult to debug backwards incompatibility problems, so this PR simply fixes the example. --- evdev-examples/uinput/Main.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/evdev-examples/uinput/Main.hs b/evdev-examples/uinput/Main.hs index fa842a9..ddb23be 100755 --- a/evdev-examples/uinput/Main.hs +++ b/evdev-examples/uinput/Main.hs @@ -1,6 +1,7 @@ module Main (main) where import Control.Monad +import Data.Maybe (mapMaybe) import qualified Evdev.Codes as Codes import Evdev.Uinput @@ -10,7 +11,7 @@ main = do dev <- newDevice "haskell-uinput-echo-example" - defaultDeviceOpts{keys = [Codes.KeyA .. Codes.KeyZ] ++ [Codes.Key1 .. Codes.Key0]} + defaultDeviceOpts{keys = mapMaybe charToEvent (['a' .. 'z'] ++ ['0'..'9'])} forever do cs <- getLine writeBatch dev [KeyEvent k a | Just k <- map charToEvent cs, a <- [Pressed, Released]]