# Work around codegen bug with GetKeyboardState \(\#41970\) · gitcafe/zed

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

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

Visibility: public

Requested revision: b4f7af066e732a1df9aba308159f4c3d3b06feb2

Requested commit: b4f7af066e732a1df9aba308159f4c3d3b06feb2

Commit: b4f7af066e732a1df9aba308159f4c3d3b06feb2

Tree: 4ab7d989fde467459eb075b0223f45129d0ac62d

Author: John Tur

Committer: GitHub

## Message

````
Work around codegen bug with GetKeyboardState (#41970)

Works around an issue, which can be reproduced in the following program:
```rs
use windows::Win32::UI::Input::KeyboardAndMouse::{GetKeyboardState, VK_CONTROL};

fn main() {
    let mut keyboard_state = [0u8; 256];
    unsafe {
        GetKeyboardState(&mut keyboard_state).unwrap();
    }

    let ctrl_down = (keyboard_state[VK_CONTROL.0 as usize] & 0x80) != 0;
    println!("Is Ctrl down: {ctrl_down}");
}
```

In debug mode, this program prints the correct answer. In release mode,
it always prints false. The optimizer appears to think that
`keyboard_state` isn't mutated and remains zeroed, and folds the
`modifier_down` comparisons to `false`.

Release Notes:

- N/A
````

## Parents

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

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