OpenClonk
C4KeyboardInput.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2005-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // Keyboard input mapping to engine functions
17 
18 #ifndef INC_C4KeyboardInput
19 #define INC_C4KeyboardInput
20 
21 // key context classifications
23 {
25  KEYSCOPE_Control = 1, // player control (e.g. NUM1 to move left on keypad control)
26  KEYSCOPE_Gui = 2, // keys used to manipulate GUI elements (e.g. Tab to cycle through controls)
27  KEYSCOPE_Fullscreen = 4, // generic fullscreen-only keys (e.g. F9 for screenshot)
28  KEYSCOPE_Console = 8, // generic console-mode only keys (e.g. Space to switch edit cursor)
29  KEYSCOPE_Generic = 16, // generic keys available in fullscreen and console mode outside GUI (e.g. F1 for music on/off)
30  KEYSCOPE_FullSMenu = 32, // fullscreen menu control. If fullscreen menu is active, this disables viewport controls (e.g. Return to close player join menu)
31  KEYSCOPE_FilmView = 64, // ownerless viewport scrolling in film mode, player switching, etc. (e.g. Enter to switch to next player)
32  KEYSCOPE_FreeView = 128, // ownerless viewport scrolling, player switching, etc. (e.g. arrow left to scroll left in view)
33  KEYSCOPE_FullSView = 256 // player fullscreen viewport
34 };
35 
36 // what can happen to keys
38 {
39  KEYEV_None = 0, // no event
40  KEYEV_Down = 1, // in response to WM_KEYDOWN or joypad button pressed
41  KEYEV_Up = 2, // in response to WM_KEYUP or joypad button released
42  KEYEV_Pressed = 3, // in response to WM_KEYPRESSED
43  KEYEV_Moved = 4, // when moving a gamepad stick
44 };
45 
46 // keyboard code
47 typedef unsigned long C4KeyCode;
48 
49 // Gamepad codes (KEY_CONTROLLER_*): Masked as 0x420000; bit 8-15 used for gamepad index
50 const C4KeyCode KEY_CONTROLLER_Mask = 0x420000;
51 
52 // Mouse codes (KEY_MOUSE_*): Masked as 0x430000; bit 8-15 used for mouse index
53 const C4KeyCode KEY_MOUSE_Mask = 0x430000;
54 
55 const C4KeyCode
56  KEY_Default = 0, // no key
57  KEY_Any = ~0, // used for default key processing
58  KEY_Undefined = (~0)^1, // used to indicate an unknown key
59  KEY_CONTROLLER_ButtonMin = 0x10, // first button
75  KEY_CONTROLLER_ButtonMax = 0x1e, // last button
76  KEY_CONTROLLER_AnyButton = 0xff, // any of the buttons above
77  KEY_CONTROLLER_AxisMin = 0x30, // first axis
86  KEY_CONTROLLER_AxisTriggerLeft = 0x39, // triggers are only positive
88  KEY_CONTROLLER_AxisMax = 0x3b, // last axis
89  KEY_MOUSE_Move = 1, // mouse control: mouse movement
90  KEY_MOUSE_Button1 = 0x10, // key index of mouse buttons + button index for more buttons
96  KEY_MOUSE_ButtonMax = KEY_MOUSE_Button1 + 0x1f, // max number of supported mouse buttons
97  KEY_MOUSE_Button1Double = 0x30, // double clicks have special events because double click speed is issued by OS
103  KEY_MOUSE_ButtonMaxDouble = KEY_MOUSE_Button1Double + 0x1f, // max number of supported mouse buttons
104  KEY_MOUSE_Wheel1Up = 0x40, // mouse control: wheel up
105  KEY_MOUSE_Wheel1Down = 0x41; // mouse control: wheel down
106 
107 inline uint8_t KEY_CONTROLLER_Button(uint8_t idx) { return KEY_CONTROLLER_ButtonMin+idx; }
108 inline uint8_t KEY_CONTROLLER_Axis(uint8_t idx, bool fMax) { return KEY_CONTROLLER_AxisMin+2*idx+fMax; }
109 
110 inline C4KeyCode KEY_Gamepad(uint8_t idButton) // convert gamepad key to Clonk-gamepad-keycode
111 {
112  // mask key as 0x004200bb, where 00 used to be the gamepad ID and bb is button ID.
113  return KEY_CONTROLLER_Mask + idButton;
114 }
115 
116 inline bool Key_IsGamepad(C4KeyCode key)
117 {
118  return (0xff0000 & key) == KEY_CONTROLLER_Mask;
119 }
120 
121 inline uint8_t Key_GetGamepad(C4KeyCode key)
122 {
123  return ((uint32_t)key >> 8) & 0xff;
124 }
125 
126 inline uint8_t Key_GetGamepadEvent(C4KeyCode key)
127 {
128  return ((uint32_t)key) & 0xff;
129 }
130 
132 {
133  // whether this is a unique button event (AnyButton not included)
135 }
136 
137 inline bool Key_IsGamepadAxis(C4KeyCode key)
138 {
139  // whether this is a unique button event (AnyButton not included)
141 }
142 
144 {
145  // get zero-based button index
147 }
148 
150 {
151  // get zero-based axis index
152  return (Key_GetGamepadEvent(key) - KEY_CONTROLLER_AxisMin) / 2;
153 }
154 
156 {
157  return !!(key & 1);
158 }
159 
160 inline C4KeyCode KEY_Mouse(uint8_t mouse_id, uint8_t mouseevent)
161 {
162  // mask key as 0x0043ggbb, where mm is mouse ID and bb is mouse event ID.
163  return KEY_MOUSE_Mask + (mouse_id<<8) + mouseevent;
164 }
165 
166 inline bool Key_IsMouse(C4KeyCode key)
167 {
168  return (0xff0000 & key) == KEY_MOUSE_Mask;
169 }
170 
171 inline uint8_t Key_GetMouse(C4KeyCode key)
172 {
173  return ((uint32_t)key >> 8) & 0xff;
174 }
175 
176 inline uint8_t Key_GetMouseEvent(C4KeyCode key)
177 {
178  return ((uint32_t)key) & uint8_t(0xff);
179 }
180 
181 bool KEY_IsModifier(C4KeyCode k);
182 
183 #ifdef _WIN32
184 #define TOUPPERIFX11(key) (key)
185 #else
186 #define TOUPPERIFX11(key) toupper(key)
187 #endif
188 
190 {
193  KEYS_Alt = 1,
197  KEYS_Undefined = 0xffff
198 };
199 
200 // extended key information containing shift state
202 {
203  C4KeyCode Key; // the key
204  DWORD dwShift; // the status of Alt, Shift, Control
205 
206  int32_t deviceId;
207 
208  // if set, the keycode was generated by a key that has been held down
209  // this flag is ignored in comparison operations
210  bool fRepeated;
211 
212  // helpers
213  static C4KeyShiftState String2KeyShift(const StdStrBuf &sName);
214  static C4KeyCode String2KeyCode(const StdStrBuf &sName);
215  static StdStrBuf KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort);
216  StdStrBuf ToString(bool fHumanReadable, bool fShort) const;
218 
219  // comparison operator for map access
220  inline bool operator <(const C4KeyCodeEx &v2) const
221  {
222  return Key < v2.Key || (Key == v2.Key && dwShift < v2.dwShift);
223  }
224 
225  inline bool operator ==(const C4KeyCodeEx &v2) const
226  {
227  return Key == v2.Key && dwShift == v2.dwShift;
228  }
229 
230  void CompileFunc(StdCompiler *pComp, StdStrBuf *pOutBuf=nullptr);
231 
232  C4KeyCodeEx(C4KeyCode Key = KEY_Default, DWORD Shift = KEYS_None, bool fIsRepeated = false, int32_t deviceId = -1);
233  static C4KeyCodeEx FromC4MC(int8_t mouse_id, int32_t button, DWORD param, bool * is_down = nullptr);
234 
235  bool IsRepeated() const { return fRepeated; }
236 
237  void FixShiftKeys(); // reduce stuff like Ctrl+RightCtrl to simply RightCtrl
238 private:
239  static C4KeyCode GetKeyByScanCode(const char *scan_code);
240 };
241 
242 // extra data associated with a key event
244 {
245  enum { KeyPos_None = 0x7fffff }; // value used to denote invalid/none key positions
246  int32_t iStrength{0}; // pressure between 0 and 100 (100 for nomal keypress)
247  int32_t game_x{KeyPos_None},game_y{KeyPos_None}, vp_x{KeyPos_None},vp_y{KeyPos_None}; // position for mouse event, landscape+viewport coordinates
248  C4KeyEventData() = default;
249  C4KeyEventData(int32_t iStrength, int32_t game_x, int32_t game_y, int32_t vp_x, int32_t vp_y) : iStrength(iStrength), game_x(game_x), game_y(game_y),vp_x(vp_x),vp_y(vp_y) {}
250  void CompileFunc(StdCompiler *pComp);
251  bool operator ==(const struct C4KeyEventData &cmp) const;
252 };
253 
254 // Helper functions for high-level GUI control mappings.
255 namespace ControllerKeys {
256 template<class T> void Any(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AnyButton))); }
257 template<class T> void Cancel(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_ButtonB))); }
258 template<class T> void Ok(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_ButtonA))); }
259 template<class T> void Left(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AxisLeftXLeft)));
261 template<class T> void Right(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AxisLeftXRight)));
263 template<class T> void Up(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AxisLeftYUp)));
265 template<class T> void Down(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AxisLeftYDown)));
267 }
268 
269 // callback interface
271 {
272 private:
273  int iRef{0};
274 public:
275  class C4CustomKey *pOriginalKey{nullptr};
276 
277 public:
278  virtual bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) = 0; // return true if processed
279 
280  friend class C4KeyboardMapping;
281 
282  // reference counter
283  inline void Ref() { ++iRef; }
284  inline void Deref() { if (!--iRef) delete this; }
285 
287  virtual ~C4KeyboardCallbackInterface() = default;
288 
289  bool IsOriginalKey(const class C4CustomKey *pCheckKey) const { return pCheckKey == pOriginalKey; }
290 };
291 
292 // callback interface
293 template <class TargetClass> class C4KeyCB : public C4KeyboardCallbackInterface
294 {
295 public:
296  typedef bool(TargetClass::*CallbackFunc)();
297 
298 protected:
299  TargetClass &rTarget;
301 
302 protected:
303  bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
304  {
305  if (!CheckCondition()) return false;
306  switch (eEv)
307  {
308  case KEYEV_Down: return pFuncDown ? (rTarget.*pFuncDown)() : false;
309  case KEYEV_Up: return pFuncUp ? (rTarget.*pFuncUp)() : false;
310  case KEYEV_Pressed: return pFuncPressed ? (rTarget.*pFuncPressed)() : false;
311  case KEYEV_Moved: return pFuncMoved ? (rTarget.*pFuncMoved)() : false;
312  default: return false;
313  }
314  }
315 
316  virtual bool CheckCondition() { return true; }
317 
318 public:
321 };
322 
323 // callback interface that passes the pressed key as a parameter
324 template <class TargetClass> class C4KeyCBPassKey : public C4KeyboardCallbackInterface
325 {
326 public:
327  typedef bool(TargetClass::*CallbackFunc)(const C4KeyCodeEx &key);
328 
329 protected:
330  TargetClass &rTarget;
332 
333 protected:
334  bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
335  {
336  if (!CheckCondition()) return false;
337  switch (eEv)
338  {
339  case KEYEV_Down: return pFuncDown ? (rTarget.*pFuncDown)(key) : false;
340  case KEYEV_Up: return pFuncUp ? (rTarget.*pFuncUp)(key) : false;
341  case KEYEV_Pressed: return pFuncPressed ? (rTarget.*pFuncPressed)(key) : false;
342  case KEYEV_Moved: return pFuncMoved ? (rTarget.*pFuncMoved)(key) : false;
343  default: return false;
344  }
345  }
346 
347  virtual bool CheckCondition() { return true; }
348 
349 public:
352 };
353 
354 // parameterized callback interface
355 template <class TargetClass, class ParameterType> class C4KeyCBEx : public C4KeyboardCallbackInterface
356 {
357 public:
358  typedef bool(TargetClass::*CallbackFunc)(ParameterType par);
359 
360 protected:
361  TargetClass &rTarget;
363  ParameterType par;
364 
365 protected:
366  bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
367  {
368  if (!CheckCondition()) return false;
369  switch (eEv)
370  {
371  case KEYEV_Down: return pFuncDown ? (rTarget.*pFuncDown)(par) : false;
372  case KEYEV_Up: return pFuncUp ? (rTarget.*pFuncUp)(par) : false;
373  case KEYEV_Pressed: return pFuncPressed ? (rTarget.*pFuncPressed)(par) : false;
374  case KEYEV_Moved: return pFuncMoved ? (rTarget.*pFuncMoved)(par) : false;
375  default: return false;
376  }
377  }
378 
379  virtual bool CheckCondition() { return true; }
380 
381 public:
382  C4KeyCBEx(TargetClass &rTarget, const ParameterType &par, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
384 };
385 
386 template <class TargetClass, class ParameterType> class C4KeyCBExPassKey : public C4KeyboardCallbackInterface
387 {
388 public:
389  typedef bool(TargetClass::*CallbackFunc)(const C4KeyCodeEx &key, const ParameterType &par);
390 
391 protected:
392  TargetClass &rTarget;
394  ParameterType par;
395 
396 protected:
397  bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
398  {
399  if (!CheckCondition()) return false;
400  switch (eEv)
401  {
402  case KEYEV_Down: return pFuncDown ? (rTarget.*pFuncDown)(key, par) : false;
403  case KEYEV_Up: return pFuncUp ? (rTarget.*pFuncUp)(key, par) : false;
404  case KEYEV_Pressed: return pFuncPressed ? (rTarget.*pFuncPressed)(key, par) : false;
405  case KEYEV_Moved: return pFuncMoved ? (rTarget.*pFuncMoved)(key, par) : false;
406  default: return false;
407  }
408  }
409 
410  virtual bool CheckCondition() { return true; }
411 
412 public:
415 };
416 
417 // one mapped keyboard entry
419 {
420 public:
421  typedef std::vector<C4KeyCodeEx> CodeList;
422 private:
423  CodeList Codes, DefaultCodes; // keyboard scancodes of OS plus shift state
424  C4KeyScope Scope; // scope in which key is processed
425  StdStrBuf Name; // custom key name; used for association in config files
426  typedef std::vector<C4KeyboardCallbackInterface *> CBVec;
427  unsigned int uiPriority; // key priority: If multiple keys of same code are defined, high prio overwrites low prio keys
428  bool is_down; // down-callbacks have been executed but up-callbacks have not (not compiled)
429 
430 public:
431  CBVec vecCallbacks; // a list of all callbacks assigned to that key
432 
433  enum Priority
434  {
435  PRIO_None = 0u,
436  PRIO_Base = 1u,
437  PRIO_Dlg = 2u,
438  PRIO_Ctrl = 3u, // controls have higher priority than dialogs in GUI
439  PRIO_CtrlOverride = 4u, // dialog handlings of keys that overwrite regular control handlings
440  PRIO_FocusCtrl = 5u, // controls override special dialog handling keys (e.g., RenameEdit)
441  PRIO_Context = 6u, // context menus above controls
442  PRIO_PlrControl = 7u, // player controls overwrite any other controls
443  PRIO_MoreThanMax = 100u // must be larger than otherwise largest used priority
444  };
445 
446 protected:
447  int iRef;
448  C4CustomKey(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority = PRIO_Base); // ctor for default key
449  C4CustomKey(CodeList rDefCodes, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority = PRIO_Base); // ctor for default key with multiple possible keys assigned
450  friend class C4Game;
451 
452 public:
453  C4CustomKey(const C4CustomKey &rCpy, bool fCopyCallbacks);
454  virtual ~C4CustomKey(); // dtor
455 
456  inline void Ref() { ++iRef; }
457  inline void Deref() { if (!--iRef) delete this; }
458 
459  const CodeList &GetCodes() const { return Codes.size() ? Codes : DefaultCodes; } // return assigned codes; default if no custom has been assigned
460  const StdStrBuf &GetName() const { return Name; }
461  C4KeyScope GetScope() const { return Scope; }
462  unsigned int GetPriority() const { return uiPriority; }
463  bool IsCodeMatched(const C4KeyCodeEx &key) const;
464 
465  void Update(const C4CustomKey *pByKey); // merge given key into this
466  bool Execute(C4KeyEventType eEv, C4KeyCodeEx key);
467 
468  bool IsDown() const { return is_down; }
469 
470  void KillCallbacks(const C4CustomKey *pOfKey); // remove any callbacks that were created by given key
471 
472  void CompileFunc(StdCompiler *pComp);
473 };
474 
475 // a key that auto-registers itself into main game keyboard input class and does dereg when deleted
476 class C4KeyBinding : protected C4CustomKey
477 {
478  // Stuffing these into an std::vector ends badly, so I've marked them non-copyable.
479  C4KeyBinding(const C4KeyBinding&) = delete;
480  C4KeyBinding& operator=(const C4KeyBinding&) = delete;
481 public:
482  C4KeyBinding(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority = PRIO_Base); // ctor for default key
483  C4KeyBinding(const CodeList &rDefCodes, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority = PRIO_Base); // ctor for default key
484  ~C4KeyBinding() override;
485 };
486 
487 // main keyboard mapping class
489 {
490 private:
491  // comparison fn for map
492  struct szLess
493  {
494  bool operator()(const char *p, const char *q) const { return p && q && (strcmp(p,q)<0); }
495  };
496 
497  typedef std::multimap<C4KeyCode, C4CustomKey *> KeyCodeMap;
498  typedef std::map<const char *, C4CustomKey *, szLess> KeyNameMap;
499  // mapping of all keys by code and name
500  KeyCodeMap KeysByCode;
501  KeyNameMap KeysByName;
502  C4KeyEventData LastKeyExtraData;
503 
504 public:
505  static bool IsValid; // global var to fix any deinitialization orders of key map and static keys
506 
507  C4KeyboardInput() { IsValid = true; }
508  ~C4KeyboardInput() { Clear(); IsValid = false; }
509 
510  void Clear(); // empty keyboard maps
511 
512 private:
513  // assign keycodes changed for a key: Update codemap
514  void UpdateKeyCodes(C4CustomKey *pKey, const C4CustomKey::CodeList &rOldCodes, const C4CustomKey::CodeList &rNewCodes);
515 
516 public:
517  void RegisterKey(C4CustomKey *pRegKey); // register key into code and name maps, or update specific key
518  void UnregisterKey(const StdStrBuf &rsName); // remove key from all maps
519  void UnregisterKeyBinding(C4CustomKey *pKey); // just remove callbacks from a key
520 
521  bool DoInput(const C4KeyCodeEx &InKey, C4KeyEventType InEvent, DWORD InScope, int32_t iStrength);
522 
523  void CompileFunc(StdCompiler *pComp);
524  bool LoadCustomConfig(); // load keyboard customization file
525 
526  C4CustomKey *GetKeyByName(const char *szKeyName);
527  StdStrBuf GetKeyCodeNameByKeyName(const char *szKeyName, bool fShort = false, int32_t iIndex = 0);
528  const C4KeyEventData &GetLastKeyExtraData() const { return LastKeyExtraData; }
529  void SetLastKeyExtraData(const C4KeyEventData &data) { LastKeyExtraData=data; }
530 };
531 
532 // keyboardinput-initializer-helper
534 
535 #endif // INC_C4KeyboardInput
536 
C4KeyCode KEY_Gamepad(uint8_t idButton)
const C4KeyCode KEY_CONTROLLER_ButtonMax
uint8_t KEY_CONTROLLER_Button(uint8_t idx)
const C4KeyCode KEY_MOUSE_Wheel1Down
uint8_t Key_GetGamepadEvent(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_ButtonRightStick
const C4KeyCode KEY_CONTROLLER_ButtonB
const C4KeyCode KEY_MOUSE_ButtonMax
const C4KeyCode KEY_Any
const C4KeyCode KEY_MOUSE_ButtonX2Double
const C4KeyCode KEY_CONTROLLER_ButtonRightShoulder
const C4KeyCode KEY_Default
const C4KeyCode KEY_CONTROLLER_AxisMin
const C4KeyCode KEY_CONTROLLER_ButtonX
const C4KeyCode KEY_CONTROLLER_ButtonDpadUp
const C4KeyCode KEY_CONTROLLER_AxisLeftXLeft
const C4KeyCode KEY_CONTROLLER_ButtonDpadLeft
const C4KeyCode KEY_MOUSE_ButtonRightDouble
const C4KeyCode KEY_MOUSE_ButtonX1
C4KeyboardInput & C4KeyboardInput_Init()
C4KeyScope
@ KEYSCOPE_None
@ KEYSCOPE_Gui
@ KEYSCOPE_FullSMenu
@ KEYSCOPE_Control
@ KEYSCOPE_FilmView
@ KEYSCOPE_FullSView
@ KEYSCOPE_Generic
@ KEYSCOPE_FreeView
@ KEYSCOPE_Fullscreen
@ KEYSCOPE_Console
const C4KeyCode KEY_MOUSE_ButtonX2
C4KeyShiftState
@ KEYS_First
@ KEYS_Shift
@ KEYS_Control
@ KEYS_Max
@ KEYS_None
@ KEYS_Alt
@ KEYS_Undefined
const C4KeyCode KEY_CONTROLLER_ButtonLeftStick
const C4KeyCode KEY_CONTROLLER_ButtonMin
const C4KeyCode KEY_CONTROLLER_ButtonStart
uint8_t Key_GetGamepadButtonIndex(C4KeyCode key)
bool Key_IsGamepadAxis(C4KeyCode key)
const C4KeyCode KEY_MOUSE_Button1
const C4KeyCode KEY_CONTROLLER_AxisRightYDown
const C4KeyCode KEY_Undefined
const C4KeyCode KEY_CONTROLLER_ButtonA
const C4KeyCode KEY_CONTROLLER_AxisLeftYDown
const C4KeyCode KEY_CONTROLLER_Mask
const C4KeyCode KEY_CONTROLLER_ButtonY
const C4KeyCode KEY_MOUSE_ButtonMiddleDouble
uint8_t Key_GetMouse(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_ButtonDpadRight
bool Key_IsGamepad(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_AxisLeftYUp
C4KeyEventType
@ KEYEV_Up
@ KEYEV_None
@ KEYEV_Pressed
@ KEYEV_Moved
@ KEYEV_Down
const C4KeyCode KEY_MOUSE_Move
bool Key_IsMouse(C4KeyCode key)
const C4KeyCode KEY_MOUSE_ButtonLeft
bool Key_IsGamepadAxisHigh(C4KeyCode key)
const C4KeyCode KEY_MOUSE_ButtonRight
const C4KeyCode KEY_MOUSE_ButtonX1Double
const C4KeyCode KEY_CONTROLLER_AxisRightXRight
const C4KeyCode KEY_CONTROLLER_AxisLeftXRight
const C4KeyCode KEY_CONTROLLER_AxisRightXLeft
C4KeyCode KEY_Mouse(uint8_t mouse_id, uint8_t mouseevent)
uint8_t Key_GetMouseEvent(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_ButtonGuide
const C4KeyCode KEY_CONTROLLER_ButtonBack
const C4KeyCode KEY_CONTROLLER_ButtonLeftShoulder
const C4KeyCode KEY_MOUSE_Button1Double
const C4KeyCode KEY_CONTROLLER_AxisTriggerLeft
const C4KeyCode KEY_MOUSE_ButtonMaxDouble
const C4KeyCode KEY_CONTROLLER_AxisRightYUp
const C4KeyCode KEY_MOUSE_ButtonLeftDouble
const C4KeyCode KEY_CONTROLLER_AxisTriggerRight
uint8_t Key_GetGamepadAxisIndex(C4KeyCode key)
uint8_t KEY_CONTROLLER_Axis(uint8_t idx, bool fMax)
const C4KeyCode KEY_CONTROLLER_AxisMax
const C4KeyCode KEY_CONTROLLER_AnyButton
const C4KeyCode KEY_MOUSE_Wheel1Up
const C4KeyCode KEY_MOUSE_ButtonMiddle
const C4KeyCode KEY_MOUSE_Mask
uint8_t Key_GetGamepad(C4KeyCode key)
bool KEY_IsModifier(C4KeyCode k)
bool Key_IsGamepadButton(C4KeyCode key)
unsigned long C4KeyCode
const C4KeyCode KEY_CONTROLLER_ButtonDpadDown
uint32_t DWORD
const CodeList & GetCodes() const
virtual ~C4CustomKey()
bool IsDown() const
std::vector< C4KeyCodeEx > CodeList
C4CustomKey(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority=PRIO_Base)
unsigned int GetPriority() const
const StdStrBuf & GetName() const
void CompileFunc(StdCompiler *pComp)
bool Execute(C4KeyEventType eEv, C4KeyCodeEx key)
void Update(const C4CustomKey *pByKey)
bool IsCodeMatched(const C4KeyCodeEx &key) const
void KillCallbacks(const C4CustomKey *pOfKey)
C4KeyScope GetScope() const
Definition: C4Game.h:33
~C4KeyBinding() override
TargetClass & rTarget
CallbackFunc pFuncUp
CallbackFunc pFuncDown
CallbackFunc pFuncPressed
bool(TargetClass::* CallbackFunc)(ParameterType par)
ParameterType par
C4KeyCBEx(TargetClass &rTarget, const ParameterType &par, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
CallbackFunc pFuncMoved
bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
virtual bool CheckCondition()
bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
CallbackFunc pFuncDown
TargetClass & rTarget
ParameterType par
bool(TargetClass::* CallbackFunc)(const C4KeyCodeEx &key, const ParameterType &par)
C4KeyCBExPassKey(TargetClass &rTarget, const ParameterType &par, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
CallbackFunc pFuncMoved
virtual bool CheckCondition()
CallbackFunc pFuncUp
CallbackFunc pFuncPressed
CallbackFunc pFuncMoved
C4KeyCB(TargetClass &rTarget, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
bool(TargetClass::* CallbackFunc)()
virtual bool CheckCondition()
CallbackFunc pFuncUp
TargetClass & rTarget
bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
CallbackFunc pFuncPressed
CallbackFunc pFuncDown
CallbackFunc pFuncUp
TargetClass & rTarget
CallbackFunc pFuncPressed
C4KeyCBPassKey(TargetClass &rTarget, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
CallbackFunc pFuncDown
bool(TargetClass::* CallbackFunc)(const C4KeyCodeEx &key)
CallbackFunc pFuncMoved
virtual bool CheckCondition()
bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
virtual ~C4KeyboardCallbackInterface()=default
virtual bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv)=0
class C4CustomKey * pOriginalKey
bool IsOriginalKey(const class C4CustomKey *pCheckKey) const
void UnregisterKeyBinding(C4CustomKey *pKey)
void UnregisterKey(const StdStrBuf &rsName)
C4CustomKey * GetKeyByName(const char *szKeyName)
static bool IsValid
void SetLastKeyExtraData(const C4KeyEventData &data)
bool DoInput(const C4KeyCodeEx &InKey, C4KeyEventType InEvent, DWORD InScope, int32_t iStrength)
void RegisterKey(C4CustomKey *pRegKey)
const C4KeyEventData & GetLastKeyExtraData() const
StdStrBuf GetKeyCodeNameByKeyName(const char *szKeyName, bool fShort=false, int32_t iIndex=0)
void CompileFunc(StdCompiler *pComp)
void Any(T &keys)
void Ok(T &keys)
void Left(T &keys)
void Down(T &keys)
void Up(T &keys)
void Cancel(T &keys)
void Right(T &keys)
static C4KeyCode String2KeyCode(const StdStrBuf &sName)
static C4KeyCodeEx FromC4MC(int8_t mouse_id, int32_t button, DWORD param, bool *is_down=nullptr)
static StdStrBuf KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort)
bool IsRepeated() const
bool operator==(const C4KeyCodeEx &v2) const
StdStrBuf ToString(bool fHumanReadable, bool fShort) const
bool operator<(const C4KeyCodeEx &v2) const
C4KeyCode Key
int32_t deviceId
C4KeyCodeEx(C4KeyCode Key=KEY_Default, DWORD Shift=KEYS_None, bool fIsRepeated=false, int32_t deviceId=-1)
static C4KeyShiftState String2KeyShift(const StdStrBuf &sName)
static StdStrBuf KeyShift2String(C4KeyShiftState eShift)
void CompileFunc(StdCompiler *pComp, StdStrBuf *pOutBuf=nullptr)
void CompileFunc(StdCompiler *pComp)
C4KeyEventData(int32_t iStrength, int32_t game_x, int32_t game_y, int32_t vp_x, int32_t vp_y)
bool operator==(const struct C4KeyEventData &cmp) const
C4KeyEventData()=default