Compare commits
9 Commits
e22588c2cb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
0dc7eb6049
|
|||
|
c34c317f4e
|
|||
|
727e0bbd72
|
|||
|
903f880c73
|
|||
|
643f75cf0a
|
|||
|
eb18dc9590
|
|||
|
36376bc5b2
|
|||
|
0366675bb3
|
|||
|
c3e8a23344
|
@ -3,37 +3,102 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::keys::Key;
|
use crate::keys::Key;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[repr(u8)]
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum Modifier {
|
pub enum Modifier {
|
||||||
LShift,
|
LCtrl = 0x01,
|
||||||
LCtrl,
|
LShift = 0x02,
|
||||||
LAlt,
|
LAlt = 0x04,
|
||||||
LMod,
|
LMod = 0x08,
|
||||||
RShift,
|
RCtrl = 0x10,
|
||||||
RCtrl,
|
RShift = 0x20,
|
||||||
RAlt,
|
RAlt = 0x40,
|
||||||
RMod,
|
RMod = 0x80,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
impl From<Modifier> for u8 {
|
||||||
|
fn from(modifier: Modifier) -> Self {
|
||||||
|
modifier as u8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Button {
|
pub enum Button {
|
||||||
Mod(Modifier),
|
Mod(Modifier),
|
||||||
Key(Key),
|
Key(Key),
|
||||||
ModTap { keycode: Key, modifier: Modifier },
|
ModTap(Key, Modifier),
|
||||||
NextLayer,
|
Compose2(CompShift, Key, CompShift, Key),
|
||||||
PrevLayer,
|
Compose3(CompShift, Key, CompShift, Key, CompShift, Key),
|
||||||
|
Layer(LayerShift, LayerDir, u16),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether a key should be shift modified as part of a compose chain.
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub enum CompShift {
|
||||||
|
/// Do not shift the key.
|
||||||
|
#[default]
|
||||||
|
Lower,
|
||||||
|
|
||||||
|
/// Shift the key.
|
||||||
|
Upper,
|
||||||
|
|
||||||
|
/// Shift the key if shift is being held down.
|
||||||
|
Variable,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub enum LayerDir {
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub enum LayerShift {
|
||||||
|
Move,
|
||||||
|
Peek,
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for Button {
|
impl Display for Button {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let cs = |cs: &CompShift| match cs {
|
||||||
|
CompShift::Lower => "",
|
||||||
|
CompShift::Upper => "⇧",
|
||||||
|
CompShift::Variable => "⇧?",
|
||||||
|
};
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Button::Mod(modifier) => Debug::fmt(&modifier, f),
|
Button::Mod(modifier) => Debug::fmt(&modifier, f),
|
||||||
Button::Key(keycode) => write!(f, "{keycode:?}"),
|
Button::Key(key) => write!(f, "{key:?}"),
|
||||||
Button::ModTap { keycode, modifier } => write!(f, "{keycode:?}/{modifier:?}"),
|
Button::ModTap(key, modifier) => write!(f, "{key:?}/{modifier}"),
|
||||||
Button::NextLayer => write!(f, "↗"),
|
Button::Compose2(cs1, k1, cs2, k2) => {
|
||||||
Button::PrevLayer => write!(f, "↘"),
|
write!(f, "⎄ {}{k1:?} {}{k2:?}", cs(cs1), cs(cs2))
|
||||||
|
}
|
||||||
|
Button::Compose3(cs1, k1, cs2, k2, cs3, k3) => {
|
||||||
|
write!(f, "⎄ {}{k1:?} {}{k2:?} {}{k3:?}", cs(cs1), cs(cs2), cs(cs3))
|
||||||
|
}
|
||||||
|
Button::Layer(..) => write!(f, "Lr"),
|
||||||
Button::None => write!(f, "Ø"),
|
Button::None => write!(f, "Ø"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Modifier {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let s = match self {
|
||||||
|
Modifier::LCtrl => "⎈",
|
||||||
|
Modifier::LShift => "⇧",
|
||||||
|
Modifier::LAlt => "⎇",
|
||||||
|
Modifier::LMod => "◆",
|
||||||
|
Modifier::RCtrl => "⎈",
|
||||||
|
Modifier::RShift => "⇧",
|
||||||
|
Modifier::RAlt => "⎇",
|
||||||
|
Modifier::RMod => "◆",
|
||||||
|
};
|
||||||
|
|
||||||
|
write!(f, "{s}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
225
src/keys.rs
225
src/keys.rs
@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
// https://usb.org/sites/default/files/hut1_3_0.pdf
|
// https://usb.org/sites/default/files/hut1_3_0.pdf
|
||||||
pub enum Key {
|
pub enum Key {
|
||||||
A = 0x04,
|
A = 0x04,
|
||||||
@ -31,33 +32,233 @@ pub enum Key {
|
|||||||
Y = 0x1C,
|
Y = 0x1C,
|
||||||
Z = 0x1D,
|
Z = 0x1D,
|
||||||
|
|
||||||
|
/// Keyboard 1 and !
|
||||||
D1 = 0x1E,
|
D1 = 0x1E,
|
||||||
|
/// Keyboard 2 and @
|
||||||
D2 = 0x1F,
|
D2 = 0x1F,
|
||||||
|
/// Keyboard 3 and #
|
||||||
D3 = 0x20,
|
D3 = 0x20,
|
||||||
|
/// Keyboard 4 and $
|
||||||
D4 = 0x21,
|
D4 = 0x21,
|
||||||
|
/// Keyboard 5 and %
|
||||||
D5 = 0x22,
|
D5 = 0x22,
|
||||||
|
/// Keyboard 6 and ∧
|
||||||
D6 = 0x23,
|
D6 = 0x23,
|
||||||
|
/// Keyboard 7 and &
|
||||||
D7 = 0x24,
|
D7 = 0x24,
|
||||||
|
/// Keyboard 8 and *
|
||||||
D8 = 0x25,
|
D8 = 0x25,
|
||||||
|
/// Keyboard 9 and (
|
||||||
D9 = 0x26,
|
D9 = 0x26,
|
||||||
|
/// Keyboard 0 and )
|
||||||
D0 = 0x27,
|
D0 = 0x27,
|
||||||
|
|
||||||
Colon = 0x33,
|
|
||||||
Apostrophe = 0x34,
|
|
||||||
Comma = 0x36,
|
|
||||||
Period = 0x37,
|
|
||||||
|
|
||||||
Space = 0x2C,
|
|
||||||
Return = 0x28,
|
Return = 0x28,
|
||||||
|
Escape = 0x29,
|
||||||
|
/// Keyboard DELETE (Backspace)
|
||||||
|
Backspace = 0x2A,
|
||||||
|
Tab = 0x2B,
|
||||||
|
|
||||||
LCtrl = 0xE0,
|
/// Keyboard Spacebar
|
||||||
RCtrl = 0xE4,
|
Space = 0x2C,
|
||||||
|
/// Keyboard - and (underscore)
|
||||||
|
Dash = 0x2D,
|
||||||
|
/// Keyboard = and +2
|
||||||
|
Equal = 0x2E,
|
||||||
|
/// Keyboard [ and {
|
||||||
|
LBracket = 0x2F,
|
||||||
|
/// Keyboard ] and }
|
||||||
|
RBracket = 0x30,
|
||||||
|
/// Keyboard \and |
|
||||||
|
BackslashPipe = 0x31,
|
||||||
|
/// Keyboard Non-US # and ̃
|
||||||
|
Pound = 0x32,
|
||||||
|
/// Keyboard ; and :
|
||||||
|
Colon = 0x33,
|
||||||
|
/// Keyboard ‘ and “
|
||||||
|
Apostrophe = 0x34,
|
||||||
|
/// Keyboard Grave Accent and Tilde
|
||||||
|
Accent = 0x35,
|
||||||
|
/// Keyboard , and <
|
||||||
|
Comma = 0x36,
|
||||||
|
/// Keyboard . and >
|
||||||
|
Period = 0x37,
|
||||||
|
/// Keyboard / and ?
|
||||||
|
Slash = 0x38,
|
||||||
|
CapsLock = 0x39,
|
||||||
|
|
||||||
LShift = 0xE1,
|
F1 = 0x3A,
|
||||||
RShift = 0xE5,
|
F2 = 0x3B,
|
||||||
|
F3 = 0x3C,
|
||||||
|
F4 = 0x3D,
|
||||||
|
F5 = 0x3E,
|
||||||
|
F6 = 0x3F,
|
||||||
|
F7 = 0x40,
|
||||||
|
F8 = 0x41,
|
||||||
|
F9 = 0x42,
|
||||||
|
F10 = 0x43,
|
||||||
|
F11 = 0x44,
|
||||||
|
F12 = 0x45,
|
||||||
|
|
||||||
LAlt = 0xE2,
|
/// Keyboard PrintScreen
|
||||||
RAlt = 0xE6,
|
PrintScreen = 0x46,
|
||||||
|
/// Keyboard Scroll Lock
|
||||||
|
ScrollLock = 0x47,
|
||||||
|
/// Keyboard Pause
|
||||||
|
Pause = 0x48,
|
||||||
|
/// Keyboard Insert
|
||||||
|
Insert = 0x49,
|
||||||
|
/// Keyboard Home
|
||||||
|
Home = 0x4A,
|
||||||
|
/// Keyboard PageUp
|
||||||
|
PageUp = 0x4B,
|
||||||
|
/// Keyboard Delete Forward
|
||||||
|
Delete = 0x4C,
|
||||||
|
/// KeyboardEnd7
|
||||||
|
End = 0x4D,
|
||||||
|
/// Keyboard PageDown7
|
||||||
|
PageDown7 = 0x4E,
|
||||||
|
/// Keyboard RightArrow7
|
||||||
|
RightArrow7 = 0x4F,
|
||||||
|
/// Keyboard LeftArrow7
|
||||||
|
LeftArrow7 = 0x50,
|
||||||
|
/// Keyboard DownArrow7
|
||||||
|
DownArrow7 = 0x51,
|
||||||
|
/// Keyboard UpArrow7
|
||||||
|
UpArrow7 = 0x52,
|
||||||
|
/// Keypad Num Lock and Clear6
|
||||||
|
KeypadNumLock = 0x53,
|
||||||
|
/// Keypad /
|
||||||
|
KeypadSlash = 0x54,
|
||||||
|
/// Keypad *
|
||||||
|
KeypadAsterisk = 0x55,
|
||||||
|
/// Keypad -
|
||||||
|
KeypadMinus = 0x56,
|
||||||
|
/// Keypad +
|
||||||
|
KeypadPlus = 0x57,
|
||||||
|
/// KeypadEnter
|
||||||
|
KeypadEnter = 0x58,
|
||||||
|
/// Keypad 1 and End
|
||||||
|
Keypad1 = 0x59,
|
||||||
|
/// Keypad 2 and Down Arrow
|
||||||
|
Keypad2 = 0x5A,
|
||||||
|
/// Keypad 3 and PageDn
|
||||||
|
Keypad3 = 0x5B,
|
||||||
|
/// Keypad 4 and Left Arrow
|
||||||
|
Keypad4 = 0x5C,
|
||||||
|
/// Keypad 5
|
||||||
|
Keypad5 = 0x5D,
|
||||||
|
/// Keypad 6 and Right Arrow
|
||||||
|
Keypad6 = 0x5E,
|
||||||
|
/// Keypad 7 and Home
|
||||||
|
Keypad7 = 0x5F,
|
||||||
|
/// Keypad 8 and Up Arrow
|
||||||
|
Keypad8 = 0x60,
|
||||||
|
/// Keypad 9 and PageUp
|
||||||
|
Keypad9 = 0x61,
|
||||||
|
/// Keypad 0 and Insert
|
||||||
|
Keypad0 = 0x62,
|
||||||
|
|
||||||
|
/// Keypad . and Delete
|
||||||
|
KbPeriod = 0x63,
|
||||||
|
/// Keyboard Non-US \ and |
|
||||||
|
NonUsBackslashPipe = 0x64,
|
||||||
|
Application = 0x65,
|
||||||
|
Power = 0x66,
|
||||||
|
/// Keypad =
|
||||||
|
KpEqual = 0x67,
|
||||||
|
F13 = 0x68,
|
||||||
|
F14 = 0x69,
|
||||||
|
F15 = 0x6A,
|
||||||
|
F16 = 0x6B,
|
||||||
|
F17 = 0x6C,
|
||||||
|
F18 = 0x6D,
|
||||||
|
F19 = 0x6E,
|
||||||
|
F20 = 0x6F,
|
||||||
|
F21 = 0x70,
|
||||||
|
F22 = 0x71,
|
||||||
|
F23 = 0x72,
|
||||||
|
F24 = 0x73,
|
||||||
|
Execute = 0x74,
|
||||||
|
Help = 0x75,
|
||||||
|
Menu = 0x76,
|
||||||
|
Select = 0x77,
|
||||||
|
Stop = 0x78,
|
||||||
|
Again = 0x79,
|
||||||
|
Undo = 0x7A,
|
||||||
|
Cut = 0x7B,
|
||||||
|
Copy = 0x7C,
|
||||||
|
Paste = 0x7D,
|
||||||
|
Find = 0x7E,
|
||||||
|
Mute = 0x7F,
|
||||||
|
VolumeUp = 0x80,
|
||||||
|
VolumeDown = 0x81,
|
||||||
|
/// Keyboard Locking Caps Lock
|
||||||
|
LockingCapsLock = 0x82,
|
||||||
|
/// Keyboard Locking Num Lock
|
||||||
|
LockingNumLock = 0x83,
|
||||||
|
/// Keyboard Locking Scroll Lock
|
||||||
|
LockingScrollLock = 0x84,
|
||||||
|
/// Keypad ,
|
||||||
|
KpComma = 0x85,
|
||||||
|
/// Keypad Equal Sign
|
||||||
|
KpEqualSIgn = 0x86,
|
||||||
|
|
||||||
|
International1 = 0x87,
|
||||||
|
International2 = 0x88,
|
||||||
|
International3 = 0x89,
|
||||||
|
International4 = 0x8A,
|
||||||
|
International5 = 0x8B,
|
||||||
|
International6 = 0x8C,
|
||||||
|
International7 = 0x8D,
|
||||||
|
International8 = 0x8E,
|
||||||
|
International9 = 0x8F,
|
||||||
|
Lang1 = 0x90,
|
||||||
|
Lang2 = 0x91,
|
||||||
|
Lang3 = 0x92,
|
||||||
|
Lang4 = 0x93,
|
||||||
|
Lang5 = 0x94,
|
||||||
|
Lang6 = 0x95,
|
||||||
|
Lang7 = 0x96,
|
||||||
|
Lang8 = 0x97,
|
||||||
|
Lang9 = 0x98,
|
||||||
|
/// Keyboard Alternative Erase
|
||||||
|
AltErase = 0x99,
|
||||||
|
/// Keyboard SysReq/Attention
|
||||||
|
SysReq = 0x9A,
|
||||||
|
Cancel = 0x9B,
|
||||||
|
Clear = 0x9C,
|
||||||
|
Prior = 0x9D,
|
||||||
|
/// Keyboard Return
|
||||||
|
Return2 = 0x9E,
|
||||||
|
/// Keyboard Separator
|
||||||
|
Separator = 0x9F,
|
||||||
|
|
||||||
|
/// Keyboard Out
|
||||||
|
Out = 0xA0,
|
||||||
|
/// Keyboard Oper
|
||||||
|
Oper = 0xA1,
|
||||||
|
/// Keyboard Clear/Again
|
||||||
|
ClearAgain = 0xA2,
|
||||||
|
/// Keyboard CrSel/Props
|
||||||
|
CrSel = 0xA3,
|
||||||
|
/// Keyboard ExSel
|
||||||
|
ExSel = 0xA4,
|
||||||
|
//
|
||||||
|
// NOTE: the usb keyboard/keypad page allegedly har characters in the rage above A4,
|
||||||
|
// like the ones below, but they don't seem to work
|
||||||
|
///// Keypad {
|
||||||
|
//LCurly = 0xB8,
|
||||||
|
///// Keypad }
|
||||||
|
//RCurly = 0xB9,
|
||||||
|
//
|
||||||
|
// NOTE: Not sure if these are required
|
||||||
|
//LCtrl = 0xE0,
|
||||||
|
//LShift = 0xE1,
|
||||||
|
//LAlt = 0xE2,
|
||||||
|
//RCtrl = 0xE4,
|
||||||
|
//RShift = 0xE5,
|
||||||
|
//RAlt = 0xE6,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Key> for u8 {
|
impl From<Key> for u8 {
|
||||||
|
|||||||
Reference in New Issue
Block a user