diff --git a/examples/event-read.rs b/examples/event-read.rs
index 2a32cefba..549e05a91 100644
--- a/examples/event-read.rs
+++ b/examples/event-read.rs
@@ -4,7 +4,9 @@
use std::io::stdout;
-use crossterm::event::poll;
+use crossterm::event::{
+ poll, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
+};
use crossterm::{
cursor::position,
event::{
@@ -70,13 +72,27 @@ fn main() -> Result<()> {
enable_raw_mode()?;
let mut stdout = stdout();
- execute!(stdout, EnableFocusChange, EnableMouseCapture)?;
+ execute!(
+ stdout,
+ EnableFocusChange,
+ EnableMouseCapture,
+ PushKeyboardEnhancementFlags(
+ KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
+ | KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES
+ | KeyboardEnhancementFlags::REPORT_EVENT_TYPES
+ )
+ )?;
if let Err(e) = print_events() {
println!("Error: {:?}\r", e);
}
- execute!(stdout, DisableFocusChange, DisableMouseCapture)?;
+ execute!(
+ stdout,
+ PopKeyboardEnhancementFlags,
+ DisableFocusChange,
+ DisableMouseCapture
+ )?;
disable_raw_mode()
}
diff --git a/src/event.rs b/src/event.rs
index e32ea9515..42411b543 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -534,12 +534,19 @@ pub enum MouseButton {
}
bitflags! {
- /// Represents key modifiers (shift, control, alt).
+ /// Represents key modifiers (shift, control, alt, etc.).
+ ///
+ /// **Note:** `SUPER`, `HYPER`, and `META` can only be read if
+ /// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
+ /// [`PushKeyboardEnhancementFlags`].
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KeyModifiers: u8 {
const SHIFT = 0b0000_0001;
const CONTROL = 0b0000_0010;
const ALT = 0b0000_0100;
+ const SUPER = 0b0000_1000;
+ const HYPER = 0b0001_0000;
+ const META = 0b0010_0000;
const NONE = 0b0000_0000;
}
}
@@ -555,10 +562,23 @@ pub enum KeyEventKind {
bitflags! {
/// Represents extra state about the key event.
+ ///
+ /// **Note:** This state can only be read if
+ /// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
+ /// [`PushKeyboardEnhancementFlags`].
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KeyEventState: u8 {
/// The key event origins from the keypad.
const KEYPAD = 0b0000_0001;
+ /// Caps Lock was enabled for this key event.
+ ///
+ /// **Note:** this is set for the initial press of Num Lock itself.
+ const CAPS_LOCK = 0b0000_1000;
+ /// Num Lock was enabled for this key event.
+ ///
+ /// **Note:** this is set for the initial press of Num Lock itself.
+ const NUM_LOCK = 0b0000_1000;
+ const NONE = 0b0000_0000;
}
}
diff --git a/src/event/sys/unix/parse.rs b/src/event/sys/unix/parse.rs
index 37d5ecf70..d96a2f366 100644
--- a/src/event/sys/unix/parse.rs
+++ b/src/event/sys/unix/parse.rs
@@ -169,6 +169,7 @@ pub(crate) fn parse_csi(buffer: &[u8]) -> Result