uidevices/keyboard/
protocol.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![expect(dead_code)]

use guid::Guid;
use zerocopy::FromBytes;
use zerocopy::Immutable;
use zerocopy::IntoBytes;
use zerocopy::KnownLayout;

// f912ad6d-2b17-48ea-bd65-f927a61c7684
pub const INTERFACE_GUID: Guid = guid::guid!("f912ad6d-2b17-48ea-bd65-f927a61c7684");

// d34b2567-b9b6-42b9-8778-0a4ec0b955bf
pub const INSTANCE_GUID: Guid = guid::guid!("d34b2567-b9b6-42b9-8778-0a4ec0b955bf");

const fn make_version(major: u16, minor: u16) -> u32 {
    (major as u32) << 16 | minor as u32
}
pub const VERSION_WIN8: u32 = make_version(1, 0);

pub const MESSAGE_PROTOCOL_REQUEST: u32 = 1;
pub const MESSAGE_PROTOCOL_RESPONSE: u32 = 2;
pub const MESSAGE_EVENT: u32 = 3;
pub const MESSAGE_SET_LED_INDICATORS: u32 = 4;

#[repr(C)]
#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
pub struct MessageHeader {
    pub message_type: u32,
}

#[repr(C)]
#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
pub struct MessageProtocolRequest {
    pub version: u32,
}

#[repr(C)]
#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
pub struct MessageLedIndicatorsState {
    pub led_flags: u16,
    pub padding: u16,
}

#[repr(C)]
#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
pub struct MessageProtocolResponse {
    pub accepted: u32,
}

#[repr(C)]
#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
pub struct MessageKeystroke {
    pub make_code: u16,
    pub padding: u16,
    pub flags: u32,
}

pub const KEYSTROKE_IS_UNICODE: u32 = 1 << 0;
pub const KEYSTROKE_IS_BREAK: u32 = 1 << 1;
pub const KEYSTROKE_IS_E0: u32 = 1 << 2;
pub const KEYSTROKE_IS_E1: u32 = 1 << 3;

pub const MAXIMUM_MESSAGE_SIZE: usize = 256;