xbmc
Key.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
16 #include "input/actions/Action.h"
18 #include "input/actions/ActionIDs.h"
19 
20 #include <stdint.h>
21 #include <string>
22 
23 // Reserved 0 - 255
24 // IRRemote.h
25 // XINPUT_IR_REMOTE-*
26 
27 /*
28  * EventServer "gamepad" keys based on original Xbox controller
29  */
30 // Analogue - don't change order
31 #define KEY_BUTTON_A 256
32 #define KEY_BUTTON_B 257
33 #define KEY_BUTTON_X 258
34 #define KEY_BUTTON_Y 259
35 #define KEY_BUTTON_BLACK 260
36 #define KEY_BUTTON_WHITE 261
37 #define KEY_BUTTON_LEFT_TRIGGER 262
38 #define KEY_BUTTON_RIGHT_TRIGGER 263
39 
40 #define KEY_BUTTON_LEFT_THUMB_STICK 264
41 #define KEY_BUTTON_RIGHT_THUMB_STICK 265
42 
43 #define KEY_BUTTON_RIGHT_THUMB_STICK_UP 266 // right thumb stick directions
44 #define KEY_BUTTON_RIGHT_THUMB_STICK_DOWN 267 // for defining different actions per direction
45 #define KEY_BUTTON_RIGHT_THUMB_STICK_LEFT 268
46 #define KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT 269
47 
48 // Digital - don't change order
49 #define KEY_BUTTON_DPAD_UP 270
50 #define KEY_BUTTON_DPAD_DOWN 271
51 #define KEY_BUTTON_DPAD_LEFT 272
52 #define KEY_BUTTON_DPAD_RIGHT 273
53 
54 #define KEY_BUTTON_START 274
55 #define KEY_BUTTON_BACK 275
56 
57 #define KEY_BUTTON_LEFT_THUMB_BUTTON 276
58 #define KEY_BUTTON_RIGHT_THUMB_BUTTON 277
59 
60 #define KEY_BUTTON_LEFT_ANALOG_TRIGGER 278
61 #define KEY_BUTTON_RIGHT_ANALOG_TRIGGER 279
62 
63 #define KEY_BUTTON_LEFT_THUMB_STICK_UP 280 // left thumb stick directions
64 #define KEY_BUTTON_LEFT_THUMB_STICK_DOWN 281 // for defining different actions per direction
65 #define KEY_BUTTON_LEFT_THUMB_STICK_LEFT 282
66 #define KEY_BUTTON_LEFT_THUMB_STICK_RIGHT 283
67 
68 // 0xF000 -> 0xF200 is reserved for the keyboard; a keyboard press is either
69 #define KEY_VKEY 0xF000 // a virtual key/functional key e.g. cursor left
70 #define KEY_UNICODE \
71  0xF200 // another printable character whose range is not included in this KEY code
72 
73 // 0xE000 -> 0xEFFF is reserved for mouse actions
74 #define KEY_VMOUSE 0xEFFF
75 
76 #define KEY_MOUSE_START 0xE000
77 #define KEY_MOUSE_CLICK 0xE000
78 #define KEY_MOUSE_RIGHTCLICK 0xE001
79 #define KEY_MOUSE_MIDDLECLICK 0xE002
80 #define KEY_MOUSE_DOUBLE_CLICK 0xE010
81 #define KEY_MOUSE_LONG_CLICK 0xE020
82 #define KEY_MOUSE_WHEEL_UP 0xE101
83 #define KEY_MOUSE_WHEEL_DOWN 0xE102
84 #define KEY_MOUSE_MOVE 0xE103
85 #define KEY_MOUSE_DRAG 0xE104
86 #define KEY_MOUSE_DRAG_START 0xE105
87 #define KEY_MOUSE_DRAG_END 0xE106
88 #define KEY_MOUSE_RDRAG 0xE107
89 #define KEY_MOUSE_RDRAG_START 0xE108
90 #define KEY_MOUSE_RDRAG_END 0xE109
91 #define KEY_MOUSE_NOOP 0xEFFF
92 #define KEY_MOUSE_END 0xEFFF
93 
94 // 0xD000 -> 0xD0FF is reserved for WM_APPCOMMAND messages
95 #define KEY_APPCOMMAND 0xD000
96 
97 #define KEY_INVALID 0xFFFF
98 
99 #define ICON_TYPE_NONE 101
100 #define ICON_TYPE_PROGRAMS 102
101 #define ICON_TYPE_MUSIC 103
102 #define ICON_TYPE_PICTURES 104
103 #define ICON_TYPE_VIDEOS 105
104 #define ICON_TYPE_FILES 106
105 #define ICON_TYPE_WEATHER 107
106 #define ICON_TYPE_SETTINGS 109
107 
108 #ifndef SWIG
109 
115 {
116 public:
117  CMouseEvent(int actionID, int state = 0, float offsetX = 0, float offsetY = 0)
118  {
119  m_id = actionID;
120  m_state = state;
121  m_offsetX = offsetX;
122  m_offsetY = offsetY;
123  };
124 
125  int m_id;
126  int m_state;
127  float m_offsetX;
128  float m_offsetY;
129 };
130 
135 class CKey
136 {
137 public:
138  CKey(void);
139  CKey(uint32_t buttonCode,
140  uint8_t leftTrigger = 0,
141  uint8_t rightTrigger = 0,
142  float leftThumbX = 0.0f,
143  float leftThumbY = 0.0f,
144  float rightThumbX = 0.0f,
145  float rightThumbY = 0.0f,
146  float repeat = 0.0f);
147  CKey(uint32_t buttonCode, unsigned int held);
148  CKey(uint32_t keycode,
149  uint8_t vkey,
150  wchar_t unicode,
151  char ascii,
152  uint32_t modifiers,
153  uint32_t lockingModifiers,
154  unsigned int held);
155  CKey(const CKey& key);
156  void Reset();
157 
158  virtual ~CKey(void);
159  CKey& operator=(const CKey& key);
160  uint8_t GetLeftTrigger() const;
161  uint8_t GetRightTrigger() const;
162  float GetLeftThumbX() const;
163  float GetLeftThumbY() const;
164  float GetRightThumbX() const;
165  float GetRightThumbY() const;
166  float GetRepeat() const;
167  bool FromKeyboard() const;
168  bool IsAnalogButton() const;
169  bool IsIRRemote() const;
170  void SetFromService(bool fromService);
171  bool GetFromService() const { return m_fromService; }
172 
173  inline uint32_t GetButtonCode() const { return m_buttonCode; }
174  inline uint32_t GetKeycode() const { return m_keycode; } // XBMCKey enum in XBMC_keysym.h
175  inline uint8_t GetVKey() const { return m_vkey; }
176  inline wchar_t GetUnicode() const { return m_unicode; }
177  inline char GetAscii() const { return m_ascii; }
178  inline uint32_t GetModifiers() const { return m_modifiers; }
179  inline uint32_t GetLockingModifiers() const { return m_lockingModifiers; }
180  inline unsigned int GetHeld() const { return m_held; }
181 
182  enum Modifier
183  {
184  MODIFIER_CTRL = 0x00010000,
185  MODIFIER_SHIFT = 0x00020000,
186  MODIFIER_ALT = 0x00040000,
187  MODIFIER_RALT = 0x00080000,
188  MODIFIER_SUPER = 0x00100000,
189  MODIFIER_META = 0X00200000,
190  MODIFIER_LONG = 0X01000000,
191  MODIFIER_NUMLOCK = 0X02000000,
192  MODIFIER_CAPSLOCK = 0X04000000,
193  MODIFIER_SCROLLLOCK = 0X08000000,
194  };
195 
196 private:
197  uint32_t m_buttonCode;
198  uint32_t m_keycode;
199  uint8_t m_vkey;
200  wchar_t m_unicode;
201  char m_ascii;
202  uint32_t m_modifiers;
203  uint32_t m_lockingModifiers;
204  unsigned int m_held;
205 
206  uint8_t m_leftTrigger;
207  uint8_t m_rightTrigger;
208  float m_leftThumbX;
209  float m_leftThumbY;
210  float m_rightThumbX;
211  float m_rightThumbY;
212  float m_repeat; // time since last keypress
213  bool m_fromService;
214 };
215 #endif // undef SWIG
Definition: Key.h:135
Simple class for mouse events.
Definition: Key.h:114