diff options
author | Wez Furlong <wez@wezfurlong.org> | 2019-12-31 08:52:27 -0800 |
---|---|---|
committer | Wez Furlong <wez@wezfurlong.org> | 2019-12-31 08:52:27 -0800 |
commit | 3b9ee0e69dcc6a43c9010972f8736cbad06c4a94 (patch) | |
tree | 275ea9e3aee82fb80f61858063a91fb53cfcdbcd | |
parent | de697432f91c79cf5c9041c3bd83cc18ae3e12ad (diff) |
Add list-keys subcommand
-rw-r--r-- | src/main.rs | 24 | ||||
-rw-r--r-- | src/mapping.rs | 2 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index c5caadb..64a83ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,9 @@ enum Opt { /// configuration ListDevices, + /// Show a list of possible KEY_XXX values + ListKeys, + /// Load a remapper config and run the remapper. /// This usually requires running as root to obtain exclusive access /// to the input devices. @@ -31,12 +34,28 @@ enum Opt { }, } +pub fn list_keys() -> Result<()> { + let mut keys: Vec<String> = EventCode::EV_KEY(KeyCode::KEY_RESERVED) + .iter() + .filter_map(|code| match code { + EventCode::EV_KEY(_) => Some(format!("{}", code)), + _ => None, + }) + .collect(); + keys.sort(); + for key in keys { + println!("{}", key); + } + Ok(()) +} + fn main() -> Result<()> { pretty_env_logger::init(); let opt = Opt::from_args(); match opt { - Opt::ListDevices => return deviceinfo::list_devices(), + Opt::ListDevices => deviceinfo::list_devices(), + Opt::ListKeys => list_keys(), Opt::Remap { config_file } => { let mapping_config = MappingConfig::from_file(&config_file).context(format!( "loading MappingConfig from {}", @@ -49,8 +68,7 @@ fn main() -> Result<()> { let device_info = deviceinfo::DeviceInfo::with_name(&mapping_config.device_name)?; let mut mapper = InputMapper::create_mapper(device_info.path, mapping_config.mappings)?; - mapper.run_mapper()?; - Ok(()) + mapper.run_mapper() } } } diff --git a/src/mapping.rs b/src/mapping.rs index 34a9615..c2dca77 100644 --- a/src/mapping.rs +++ b/src/mapping.rs @@ -59,7 +59,7 @@ impl Into<KeyCode> for KeyCodeWrapper { #[derive(Error, Debug)] pub enum ConfigError { - #[error("Invalid key `{0}`")] + #[error("Invalid key `{0}`. Use `evremap list-keys` to see possible keys.")] InvalidKey(String), #[error("Impossible: parsed KEY_XXX but not into an EV_KEY")] ImpossibleParseKey, |