# windows: Better keyboard input support \(\#9180\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/36cbfbfb9493f6fa2ff1c45fe35feca86af8cf28)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 36cbfbfb9493f6fa2ff1c45fe35feca86af8cf28

Requested commit: 36cbfbfb9493f6fa2ff1c45fe35feca86af8cf28

Commit: 36cbfbfb9493f6fa2ff1c45fe35feca86af8cf28

Tree: 7a2f18a8a5d93ff613d891dce42fe08c8168f1aa

Author: 张小白

Committer: GitHub

## Message

````
windows: Better keyboard input support (#9180)

### Description

Currently, there are some issues with input handling on Windows:

#### 1. Direct crash when encountering IME input.



https://github.com/zed-industries/zed/assets/14981363/598f7272-1948-4a42-99c5-2ef7b9162a1e


#### 2. Handling messages every 1/60 seconds in the main thread. Despite
being named "immediate_handle," it's not exactly immediate.

```rust
// actually halt here
let wait_result =
    unsafe { DCompositionWaitForCompositorClock(Some(&[self.inner.event]), INFINITE) };

// compositor clock ticked so we should draw a frame
if wait_result == 1 {
    unsafe { invalidate_thread_windows(GetCurrentThreadId()) };

    while unsafe { PeekMessageW(&mut msg, HWND::default(), 0, 0, PM_REMOVE) }.as_bool()
```

#### 3. According to Windows recommendations, character input should be
obtained using `WM_CHAR` instead of `WM_KEYDOWN`. Additionally, there
are problems with the handling within `WM_CHAR`.

```rust
fn handle_char_msg(&self, wparam: WPARAM) -> LRESULT {
        let mut callbacks = self.callbacks.borrow_mut();
        if let Some(callback) = callbacks.input.as_mut() {
            let modifiers = self.current_modifiers();
            let msg_char = wparam.0 as u8 as char; // these are u16 chars, cant treat them as u8
```

And, we don't handle `WM_SYSKEYDOWN` properly, which leads to `Alt + F4`
not working.

Release Notes:

- N/A
````

## Parents

- [2abb5aeaf22840e505bd1a119a0fef458d8a15b2](https://git.cafe/gitcafe/zed/commit/2abb5aeaf22840e505bd1a119a0fef458d8a15b2?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/36cbfbfb9493f6fa2ff1c45fe35feca86af8cf28?format=markdown)
