Add Caps Lock support (#30470)

Closes #21700

Release Notes:

- Added caps lock support and show a warning if the user is entering an
SSH password with Caps Lock enabled

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: 张小白 <364772080@qq.com>
This commit is contained in:
Maxim Zaks
2025-06-18 00:43:33 +00:00
committed by GitHub
co-authored by Mikayla Maki Mikayla Maki 张小白
parent e47c48fd3b
commit 90aa99bb14
16 changed files with 146 additions and 31 deletions
@@ -1227,6 +1227,7 @@ where
{
let virtual_key = VIRTUAL_KEY(wparam.loword());
let mut modifiers = current_modifiers();
let capslock = current_capslock();
match virtual_key {
VK_SHIFT | VK_CONTROL | VK_MENU | VK_LWIN | VK_RWIN => {
@@ -1239,6 +1240,7 @@ where
state.last_reported_modifiers = Some(modifiers);
Some(PlatformInput::ModifiersChanged(ModifiersChangedEvent {
modifiers,
capslock,
}))
}
vkey => {
@@ -1371,6 +1373,12 @@ pub(crate) fn current_modifiers() -> Modifiers {
}
}
#[inline]
pub(crate) fn current_capslock() -> Capslock {
let on = unsafe { GetKeyState(VK_CAPITAL.0 as i32) & 1 } > 0;
Capslock { on: on }
}
fn get_client_area_insets(
handle: HWND,
is_maximized: bool,
@@ -559,6 +559,10 @@ impl PlatformWindow for WindowsWindow {
current_modifiers()
}
fn capslock(&self) -> Capslock {
current_capslock()
}
fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {
self.0.state.borrow_mut().input_handler = Some(input_handler);
}