arcdps\extras/
keybinds.rs

1//! Keybind information provided by Unofficial Extras.
2
3use num_enum::{IntoPrimitive, TryFromPrimitive};
4
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8#[cfg(feature = "strum")]
9use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
10
11/// Keybind change event.
12#[derive(Debug, Clone)]
13#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14pub struct KeybindChange {
15    /// Game control which changed.
16    pub control: Control,
17
18    /// Index in settings.
19    pub index: i32,
20
21    /// New key.
22    pub key: Key,
23
24    /// Whether the Shift modifier is used.
25    pub mod_shift: bool,
26
27    /// Whether the Ctrl modifier is used.
28    pub mod_ctrl: bool,
29
30    /// Whether the Alt modifier is used.
31    pub mod_alt: bool,
32}
33
34impl From<RawKeybindChange> for KeybindChange {
35    #[inline]
36    fn from(raw: RawKeybindChange) -> Self {
37        let modifier = raw.key.modifier;
38        Self {
39            control: raw.control,
40            index: raw.index,
41            key: raw.key.into(),
42            mod_shift: modifier & Modifier::Shift as i32 == 1,
43            mod_ctrl: modifier & Modifier::Ctrl as i32 == 1,
44            mod_alt: modifier & Modifier::Alt as i32 == 1,
45        }
46    }
47}
48
49/// A key used by the game.
50///
51/// This can be a [`MouseCode`], [`KeyCode`] or an [`Unknown`](Self::Unknown) code.
52#[derive(Debug, Clone)]
53#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
54pub enum Key {
55    /// An unknown type of key.
56    Unknown(i32),
57
58    /// A mouse button.
59    Mouse(MouseCode),
60
61    /// A keyboard key.
62    Key(KeyCode),
63}
64
65impl From<RawKey> for Key {
66    #[inline]
67    fn from(raw: RawKey) -> Self {
68        match raw.device_type {
69            DeviceType::Unset => Self::Unknown(raw.code),
70            DeviceType::Mouse => match raw.code.try_into() {
71                Ok(code) => Self::Mouse(code),
72                Err(_) => Self::Unknown(raw.code),
73            },
74            DeviceType::Keyboard => match raw.code.try_into() {
75                Ok(code) => Self::Key(code),
76                Err(_) => Self::Unknown(raw.code),
77            },
78        }
79    }
80}
81
82/// A keybind used by the game.
83///
84/// This contains the `primary`as well as `secondary` [`Key`] for a [`Control`].
85#[derive(Debug, Clone)]
86#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
87pub struct Keybind {
88    /// Primary [`Key`] for this bind.
89    pub primary: Key,
90
91    /// Secondary [`Key`] for this bind.
92    pub secondary: Key,
93}
94
95impl From<RawKeybind> for Keybind {
96    #[inline]
97    fn from(raw: RawKeybind) -> Self {
98        Self {
99            primary: raw.primary.into(),
100            secondary: raw.secondary.into(),
101        }
102    }
103}
104
105/// Raw keybind change.
106#[derive(Debug, Clone)]
107#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
108#[repr(C)]
109pub struct RawKeybindChange {
110    /// Game control which changed.
111    pub control: Control,
112
113    /// Index in settings.
114    pub index: i32,
115
116    /// New key.
117    pub key: RawKey,
118}
119
120/// Raw key information.
121#[derive(Debug, Clone)]
122#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
123#[repr(C)]
124pub struct RawKey {
125    /// Device.
126    pub device_type: DeviceType,
127
128    /// Key code.
129    pub code: i32,
130
131    /// Key modifiers.
132    pub modifier: i32,
133}
134
135/// Raw keybind.
136#[derive(Debug, Clone)]
137#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
138#[repr(C)]
139pub struct RawKeybind {
140    /// Primary keybind.
141    pub primary: RawKey,
142
143    /// Secondary keybind.
144    pub secondary: RawKey,
145}
146
147/// A control (player action) used by the game.
148#[derive(
149    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
150)]
151#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
152#[cfg_attr(
153    feature = "strum",
154    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
155)]
156#[repr(i32)]
157#[allow(non_camel_case_types)]
158pub enum Control {
159    // Movement tab
160    Movement_MoveForward = 0,
161    Movement_MoveBackward = 1,
162    Movement_StrafeLeft = 2,
163    Movement_StrafeRight = 3,
164    Movement_TurnLeft = 4,
165    Movement_TurnRight = 5,
166    Movement_Dodge = 6,
167    Movement_Autorun = 7,
168    Movement_Walk = 8,
169    Movement_Jump = 9,
170    Movement_SwimUp = 10,
171    Movement_SwimDown = 11,
172    Movement_AboutFace = 12,
173
174    // Skills tab
175    Skills_SwapWeapons = 17,
176    Skills_WeaponSkill1 = 18,
177    Skills_WeaponSkill2 = 19,
178    Skills_WeaponSkill3 = 20,
179    Skills_WeaponSkill4 = 21,
180    Skills_WeaponSkill5 = 22,
181    Skills_HealingSkill = 23,
182    Skills_UtilitySkill1 = 24,
183    Skills_UtilitySkill2 = 25,
184    Skills_UtilitySkill3 = 26,
185    Skills_EliteSkill = 27,
186    Skills_ProfessionSkill1 = 28,
187    Skills_ProfessionSkill2 = 29,
188    Skills_ProfessionSkill3 = 30,
189    Skills_ProfessionSkill4 = 31,
190    Skills_ProfessionSkill5 = 79,
191    Skills_ProfessionSkill6 = 201,
192    Skills_ProfessionSkill7 = 202,
193    Skills_SpecialAction = 82,
194
195    // Targeting tab
196    Targeting_AlertTarget = 131,
197    Targeting_CallTarget = 32,
198    Targeting_TakeTarget = 33,
199    Targeting_SetPersonalTarget = 199,
200    Targeting_TakePersonalTarget = 200,
201    Targeting_NearestEnemy = 34,
202    Targeting_NextEnemy = 35,
203    Targeting_PreviousEnemy = 36,
204    Targeting_NearestAlly = 37,
205    Targeting_NextAlly = 38,
206    Targeting_PreviousAlly = 39,
207    Targeting_LockAutotarget = 40,
208    Targeting_SnapGroundTarget = 80,
209    Targeting_ToggleSnapGroundTarget = 115,
210    Targeting_DisableAutotargeting = 116,
211    Targeting_ToggleAutotargeting = 117,
212    Targeting_AllyTargetingMode = 197,
213    Targeting_ToggleAllyTargetingMode = 198,
214
215    // UI Tab
216    UI_BlackLionTradingDialog = 41,
217    UI_ContactsDialog = 42,
218    UI_GuildDialog = 43,
219    UI_HeroDialog = 44,
220    UI_InventoryDialog = 45,
221    UI_PetDialog = 46,
222    UI_LogOut = 47,
223    UI_MailDialog = 71,
224    UI_OptionsDialog = 48,
225    UI_PartyDialog = 49,
226    UI_PvPPanel = 73,
227    UI_PvPBuild = 75,
228    UI_Scoreboard = 50,
229    UI_InformationDialog = 51,
230    UI_Show_HideChat = 70,
231    UI_ChatCommand = 52,
232    UI_ChatMessage = 53,
233    UI_ChatReply = 54,
234    UI_ShowHideUI = 55,
235    UI_ShowHideSquadBroadcastChat = 85,
236    UI_SquadBroadcastChatCommand = 83,
237    UI_SquadBroadcastMessage = 84,
238
239    // Camera Tab
240    Camera_FreeCamera = 13,
241    Camera_ZoomIn = 14,
242    Camera_ZoomOut = 15,
243    Camera_LookBehind = 16,
244    Camera_ToggleActionCamera = 78,
245    Camera_DisableActionCamera = 114,
246
247    // Screenshot Tab
248    Screenshot_Normal = 56,
249    Screenshot_Stereoscopic = 57,
250
251    // Map Tab
252    Map_OpenClose = 59,
253    Map_Recenter = 60,
254    Map_FloorDown = 61,
255    Map_FloorUp = 62,
256    Map_ZoomIn = 63,
257    Map_ZoomOut = 64,
258
259    // Mounts Tab
260    Mounts_MountDismount = 152,
261    Mounts_MountAbility1 = 130,
262    Mounts_MountAbility2 = 153,
263    Mounts_Raptor = 155,
264    Mounts_Springer = 156,
265    Mounts_Skimmer = 157,
266    Mounts_Jackal = 158,
267    Mounts_Griffon = 159,
268    Mounts_RollerBeetle = 161,
269    Mounts_Warclaw = 169,
270    Mounts_Skyscale = 170,
271    Mounts_Turtle = 203,
272
273    // Spectators Tab
274    Spectators_NearestFixedCamera = 102,
275    Spectators_NearestPlayer = 103,
276    Spectators_RedPlayer1 = 104,
277    Spectators_RedPlayer2 = 105,
278    Spectators_RedPlayer3 = 106,
279    Spectators_RedPlayer4 = 107,
280    Spectators_RedPlayer5 = 108,
281    Spectators_BluePlayer1 = 109,
282    Spectators_BluePlayer2 = 110,
283    Spectators_BluePlayer3 = 111,
284    Spectators_BluePlayer4 = 112,
285    Spectators_BluePlayer5 = 113,
286    Spectators_FreeCamera = 120,
287    Spectators_FreeCameraBoost = 127,
288    Spectators_FreeCameraForward = 121,
289    Spectators_FreeCameraBackward = 122,
290    Spectators_FreeCameraLeft = 123,
291    Spectators_FreeCameraRight = 124,
292    Spectators_FreeCameraUp = 125,
293    Spectators_FreeCameraDown = 126,
294
295    // Squad Tab
296    Squad_Location_Arrow = 86,
297    Squad_Location_Circle = 87,
298    Squad_Location_Heart = 88,
299    Squad_Location_Square = 89,
300    Squad_Location_Star = 90,
301    Squad_Location_Spiral = 91,
302    Squad_Location_Triangle = 92,
303    Squad_Location_X = 93,
304    Squad_ClearAllLocationMarkers = 119,
305    Squad_Object_Arrow = 94,
306    Squad_Object_Circle = 95,
307    Squad_Object_Heart = 96,
308    Squad_Object_Square = 97,
309    Squad_Object_Star = 98,
310    Squad_Object_Spiral = 99,
311    Squad_Object_Triangle = 100,
312    Squad_Object_X = 101,
313    Squad_ClearAllObjectMarkers = 118,
314
315    // Mastery Skills Tab
316    MasterySkills_ActivateMasterySkill = 196,
317    MasterySkills_StartFishing = 204,
318    MasterySkills_SummonSkiff = 205,
319    MasterySkills_SetJadeBotWaypoint = 206,
320
321    // Miscellaneous Tab
322    Miscellaneous_AoELoot = 74,
323    Miscellaneous_Interact = 65,
324    Miscellaneous_ShowEnemyNames = 66,
325    Miscellaneous_ShowAllyNames = 67,
326    Miscellaneous_StowDrawWeapon = 68,
327    Miscellaneous_ToggleLanguage = 69,
328    Miscellaneous_RangerPetCombatToggle = 76,
329    Miscellaneous_ToggleFullScreen = 160,
330    Miscellaneous_EquipUnequipNovelty = 162,
331    Miscellaneous_ActivateChair = 163,
332    Miscellaneous_ActivateMusicalInstrument = 164,
333    Miscellaneous_ActivateHeldItem = 165,
334    Miscellaneous_ActivateToy = 166,
335    Miscellaneous_ActivateTonic = 167,
336
337    // Templates Tab
338    Templates_BuildTemplate1 = 171,
339    Templates_BuildTemplate2 = 172,
340    Templates_BuildTemplate3 = 173,
341    Templates_BuildTemplate4 = 174,
342    Templates_BuildTemplate5 = 175,
343    Templates_BuildTemplate6 = 176,
344    Templates_BuildTemplate7 = 177,
345    Templates_BuildTemplate8 = 178,
346    Templates_EquipmentTemplate1 = 182,
347    Templates_EquipmentTemplate2 = 183,
348    Templates_EquipmentTemplate3 = 184,
349    Templates_EquipmentTemplate4 = 185,
350    Templates_EquipmentTemplate5 = 186,
351    Templates_EquipmentTemplate6 = 187,
352    Templates_EquipmentTemplate7 = 188,
353    Templates_EquipmentTemplate8 = 189,
354}
355
356/// Custom key codes.
357///
358/// Some of them are not usable like [`F13`](Self::F32) to [`F35`](Self::F35) or [`Print`](Self::Print).
359///
360/// Names are based upon US keyboard layout.
361/// Site to translate it to other languages: <http://kbdlayout.info>
362#[derive(
363    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
364)]
365#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
366#[cfg_attr(
367    feature = "strum",
368    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
369)]
370#[repr(i32)]
371pub enum KeyCode {
372    LeftAlt = 0,
373    LeftCtrl = 1,
374    LeftShift = 2,
375    Quote = 3,
376    Hash = 4,
377    CapsLock = 5,
378    Colon = 6,
379    Minus = 7,
380    Equals = 8,
381    Escape = 9,
382    OpenBracket = 10,
383    NumLock = 11,
384    Period = 12,
385    CloseBracket = 13,
386    Semicolon = 14,
387    Slash = 15,
388    Print = 16,
389    Tilde = 17,
390    Backspace = 18,
391    Delete = 19,
392    Enter = 20,
393    Space = 21,
394    Tab = 22,
395    End = 23,
396    Home = 24,
397    Insert = 25,
398    Next = 26,
399    Prior = 27,
400    ArrowDown = 28,
401    ArrowLeft = 29,
402    ArrowRight = 30,
403    ArrowUp = 31,
404    F1 = 32,
405    F2 = 33,
406    F3 = 34,
407    F4 = 35,
408    F5 = 36,
409    F6 = 37,
410    F7 = 38,
411    F8 = 39,
412    F9 = 40,
413    F10 = 41,
414    F11 = 42,
415    F12 = 43,
416    Number0 = 48,
417    Number1 = 49,
418    Number2 = 50,
419    Number3 = 51,
420    Number4 = 52,
421    Number5 = 53,
422    Number6 = 54,
423    Number7 = 55,
424    Number8 = 56,
425    Number9 = 57,
426    A = 65,
427    B = 66,
428    C = 67,
429    D = 68,
430    E = 69,
431    F = 70,
432    G = 71,
433    H = 72,
434    I = 73,
435    J = 74,
436    K = 75,
437    L = 76,
438    M = 77,
439    N = 78,
440    O = 79,
441    P = 80,
442    Q = 81,
443    R = 82,
444    S = 83,
445    T = 84,
446    U = 85,
447    V = 86,
448    W = 87,
449    X = 88,
450    Y = 89,
451    Z = 90,
452    PlusNum = 91,
453    DecimalNum = 92,
454    DivideNum = 93,
455    MultiplyNum = 94,
456    Number0Num = 95,
457    Number1Num = 96,
458    Number2Num = 97,
459    Number3Num = 98,
460    Number4Num = 99,
461    Number5Num = 100,
462    Number6Num = 101,
463    Number7Num = 102,
464    Number8Num = 103,
465    Number9Num = 104,
466    EnterNum = 105,
467    MinusNum = 106,
468    ImeKey1 = 107,
469    ImeKey2 = 108,
470    RightAlt = 109,
471    RightCtrl = 110,
472    Backslash = 111,
473    F13 = 112,
474    F14 = 113,
475    F15 = 114,
476    F16 = 115,
477    F17 = 116,
478    F18 = 117,
479    F19 = 118,
480    F20 = 119,
481    F21 = 120,
482    F22 = 121,
483    F23 = 122,
484    F24 = 123,
485    F25 = 124,
486    F26 = 125,
487    F27 = 126,
488    F28 = 127,
489    F29 = 128,
490    F30 = 129,
491    F31 = 130,
492    F32 = 131,
493    F33 = 132,
494    F34 = 133,
495    F35 = 134,
496    RightShift = 135,
497    Eject = 136,
498    EqualNum = 137,
499    ClearNum = 138,
500    LeftCmd = 139,
501    Function = 140,
502    RightCmd = 141,
503
504    // additional, not used by GW2
505    Scroll = 200,
506    Pause = 201,
507    LeftWin = 202,
508    RightWin = 203,
509    Menu = 204,
510}
511
512/// Custom mouse codes.
513#[derive(
514    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
515)]
516#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
517#[cfg_attr(
518    feature = "strum",
519    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
520)]
521#[repr(i32)]
522pub enum MouseCode {
523    Mouse1 = 0,
524    Mouse3 = 1,
525    Mouse2 = 2,
526    Mouse4 = 3,
527    Mouse5 = 4,
528    Mouse6 = 5,
529    Mouse7 = 6,
530    Mouse8 = 7,
531    Mouse9 = 8,
532    Mouse10 = 9,
533    Mouse11 = 10,
534    Mouse12 = 11,
535    Mouse13 = 12,
536    Mouse14 = 13,
537    Mouse15 = 14,
538    Mouse16 = 15,
539    Mouse17 = 16,
540    Mouse18 = 17,
541    Mouse19 = 18,
542    Mouse20 = 19,
543}
544
545/// Device type.
546#[derive(
547    Debug,
548    Default,
549    Clone,
550    Copy,
551    PartialEq,
552    Eq,
553    PartialOrd,
554    Ord,
555    Hash,
556    IntoPrimitive,
557    TryFromPrimitive,
558)]
559#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
560#[cfg_attr(
561    feature = "strum",
562    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
563)]
564#[repr(i32)]
565pub enum DeviceType {
566    #[default]
567    Unset = 0,
568    Mouse = 1,
569    Keyboard = 2,
570}
571
572/// Key modifiers.
573#[derive(
574    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
575)]
576#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
577#[cfg_attr(
578    feature = "strum",
579    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
580)]
581#[repr(i32)]
582pub enum Modifier {
583    Shift = 1,
584    Ctrl = 2,
585    Alt = 4,
586}