Support key release events for windows. (#745)
This commit is contained in:
parent
a993a98291
commit
318f810a39
@ -134,20 +134,14 @@ impl ScreenBufferCursor {
|
||||
if x < 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!(
|
||||
"Argument Out of Range Exception when setting cursor position to X: {}",
|
||||
x
|
||||
),
|
||||
format!("Argument Out of Range Exception when setting cursor position to X: {x}"),
|
||||
));
|
||||
}
|
||||
|
||||
if y < 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!(
|
||||
"Argument Out of Range Exception when setting cursor position to Y: {}",
|
||||
y
|
||||
),
|
||||
format!("Argument Out of Range Exception when setting cursor position to Y: {y}"),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -643,7 +643,9 @@ pub struct KeyEvent {
|
||||
pub modifiers: KeyModifiers,
|
||||
/// Kind of event.
|
||||
///
|
||||
/// Only set if [`KeyboardEnhancementFlags::REPORT_EVENT_TYPES`] has been enabled with [`PushKeyboardEnhancementFlags`].
|
||||
/// Only set if:
|
||||
/// - Unix: [`KeyboardEnhancementFlags::REPORT_EVENT_TYPES`] has been enabled with [`PushKeyboardEnhancementFlags`].
|
||||
/// - Windows: always
|
||||
pub kind: KeyEventKind,
|
||||
/// Keyboard state.
|
||||
///
|
||||
|
@ -13,7 +13,7 @@ use winapi::um::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEventKind},
|
||||
event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers, MouseButton, MouseEventKind},
|
||||
Result,
|
||||
};
|
||||
|
||||
@ -221,7 +221,12 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option<WindowsKeyEvent>
|
||||
// values.
|
||||
let ch = std::char::from_u32(unicode_scalar_value as u32).unwrap();
|
||||
let key_code = KeyCode::Char(ch);
|
||||
let key_event = KeyEvent::new(key_code, modifiers);
|
||||
let kind = if key_event.key_down {
|
||||
KeyEventKind::Press
|
||||
} else {
|
||||
KeyEventKind::Release
|
||||
};
|
||||
let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind);
|
||||
return Some(WindowsKeyEvent::KeyEvent(key_event));
|
||||
}
|
||||
}
|
||||
@ -235,10 +240,6 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option<WindowsKeyEvent>
|
||||
return None;
|
||||
}
|
||||
|
||||
if !key_event.key_down {
|
||||
return None;
|
||||
}
|
||||
|
||||
let parse_result = match virtual_key_code {
|
||||
VK_SHIFT | VK_CONTROL | VK_MENU => None,
|
||||
VK_BACK => Some(KeyCode::Backspace),
|
||||
@ -283,7 +284,12 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option<WindowsKeyEvent>
|
||||
};
|
||||
|
||||
if let Some(key_code) = parse_result {
|
||||
let key_event = KeyEvent::new(key_code, modifiers);
|
||||
let kind = if key_event.key_down {
|
||||
KeyEventKind::Press
|
||||
} else {
|
||||
KeyEventKind::Release
|
||||
};
|
||||
let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind);
|
||||
return Some(WindowsKeyEvent::KeyEvent(key_event));
|
||||
}
|
||||
|
||||
|
@ -114,8 +114,8 @@ impl fmt::Display for Colored {
|
||||
Color::DarkCyan => f.write_str("5;6"),
|
||||
Color::White => f.write_str("5;15"),
|
||||
Color::Grey => f.write_str("5;7"),
|
||||
Color::Rgb { r, g, b } => write!(f, "2;{};{};{}", r, g, b),
|
||||
Color::AnsiValue(val) => write!(f, "5;{}", val),
|
||||
Color::Rgb { r, g, b } => write!(f, "2;{r};{g};{b}"),
|
||||
Color::AnsiValue(val) => write!(f, "5;{val}"),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
@ -195,13 +195,13 @@ pub(crate) fn set_size(width: u16, height: u16) -> Result<()> {
|
||||
if width > bounds.x {
|
||||
return Err(ErrorKind::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
format!("terminal width {} too large", width),
|
||||
format!("terminal width {width} too large"),
|
||||
));
|
||||
}
|
||||
if height > bounds.y {
|
||||
return Err(ErrorKind::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
format!("terminal height {} too large", height),
|
||||
format!("terminal height {height} too large"),
|
||||
));
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ pub(crate) fn set_window_title(title: impl fmt::Display) -> Result<()> {
|
||||
}
|
||||
|
||||
let mut title_utf16 = Utf16Encoder(Vec::new());
|
||||
write!(title_utf16, "{}", title).expect("formatting failed");
|
||||
write!(title_utf16, "{title}").expect("formatting failed");
|
||||
title_utf16.0.push(0);
|
||||
let title = title_utf16.0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user