OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 
182 #ifdef _WIN32
183 #define TOUPPERIFX11(key) (key)
184 #else
185 #define TOUPPERIFX11(key) toupper(key)
186 #endif
187 
189 {
192  KEYS_Alt = 1,
196  KEYS_Undefined = 0xffff
197 };
198 
199 // extended key information containing shift state
201 {
202  C4KeyCode Key; // the key
203  DWORD dwShift; // the status of Alt, Shift, Control
204 
205  int32_t deviceId;
206 
207  // if set, the keycode was generated by a key that has been held down
208  // this flag is ignored in comparison operations
209  bool fRepeated;
210 
211  // helpers
212  static C4KeyShiftState String2KeyShift(const StdStrBuf &sName);
213  static C4KeyCode String2KeyCode(const StdStrBuf &sName);
214  static StdStrBuf KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort);
215  StdStrBuf ToString(bool fHumanReadable, bool fShort) const;
217 
218  // comparison operator for map access
219  inline bool operator <(const C4KeyCodeEx &v2) const
220  {
221  return Key < v2.Key || (Key == v2.Key && dwShift < v2.dwShift);
222  }
223 
224  inline bool operator ==(const C4KeyCodeEx &v2) const
225  {
226  return Key == v2.Key && dwShift == v2.dwShift;
227  }
228 
229  void CompileFunc(StdCompiler *pComp, StdStrBuf *pOutBuf=nullptr);
230 
231  C4KeyCodeEx(C4KeyCode Key = KEY_Default, C4KeyShiftState Shift = KEYS_None, bool fIsRepeated = false, int32_t deviceId = -1);
232 
233  bool IsRepeated() const { return fRepeated; }
234 
235  void FixShiftKeys(); // reduce stuff like Ctrl+RightCtrl to simply RightCtrl
236 private:
237  static C4KeyCode GetKeyByScanCode(const char *scan_code);
238 };
239 
240 // extra data associated with a key event
242 {
243  enum { KeyPos_None = 0x7fffff }; // value used to denote invalid/none key positions
244  int32_t iStrength{0}; // pressure between 0 and 100 (100 for nomal keypress)
245  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
246  C4KeyEventData() = default;
247  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) {}
248  void CompileFunc(StdCompiler *pComp);
249  bool operator ==(const struct C4KeyEventData &cmp) const;
250 };
251 
252 // Helper functions for high-level GUI control mappings.
253 namespace ControllerKeys {
254 template<class T> void Any(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AnyButton))); }
255 template<class T> void Cancel(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_ButtonB))); }
256 template<class T> void Ok(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_ButtonA))); }
257 template<class T> void Left(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AxisLeftXLeft)));
259 template<class T> void Right(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AxisLeftXRight)));
261 template<class T> void Up(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AxisLeftYUp)));
263 template<class T> void Down(T &keys) { keys.push_back(C4KeyCodeEx(KEY_Gamepad(KEY_CONTROLLER_AxisLeftYDown)));
265 }
266 
267 // callback interface
269 {
270 private:
271  int iRef{0};
272 public:
273  class C4CustomKey *pOriginalKey{nullptr};
274 
275 public:
276  virtual bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) = 0; // return true if processed
277 
278  friend class C4KeyboardMapping;
279 
280  // reference counter
281  inline void Ref() { ++iRef; }
282  inline void Deref() { if (!--iRef) delete this; }
283 
284  C4KeyboardCallbackInterface() = default;
285  virtual ~C4KeyboardCallbackInterface() = default;
286 
287  bool IsOriginalKey(const class C4CustomKey *pCheckKey) const { return pCheckKey == pOriginalKey; }
288 };
289 
290 // callback interface
291 template <class TargetClass> class C4KeyCB : public C4KeyboardCallbackInterface
292 {
293 public:
294  typedef bool(TargetClass::*CallbackFunc)();
295 
296 protected:
297  TargetClass &rTarget;
299 
300 protected:
301  bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
302  {
303  if (!CheckCondition()) return false;
304  switch (eEv)
305  {
306  case KEYEV_Down: return pFuncDown ? (rTarget.*pFuncDown)() : false;
307  case KEYEV_Up: return pFuncUp ? (rTarget.*pFuncUp)() : false;
308  case KEYEV_Pressed: return pFuncPressed ? (rTarget.*pFuncPressed)() : false;
309  case KEYEV_Moved: return pFuncMoved ? (rTarget.*pFuncMoved)() : false;
310  default: return false;
311  }
312  }
313 
314  virtual bool CheckCondition() { return true; }
315 
316 public:
317  C4KeyCB(TargetClass &rTarget, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
318  : rTarget(rTarget), pFuncDown(pFuncDown), pFuncUp(pFuncUp), pFuncPressed(pFuncPressed), pFuncMoved(pFuncMoved) {}
319 };
320 
321 // callback interface that passes the pressed key as a parameter
322 template <class TargetClass> class C4KeyCBPassKey : public C4KeyboardCallbackInterface
323 {
324 public:
325  typedef bool(TargetClass::*CallbackFunc)(const C4KeyCodeEx &key);
326 
327 protected:
328  TargetClass &rTarget;
330 
331 protected:
332  bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
333  {
334  if (!CheckCondition()) return false;
335  switch (eEv)
336  {
337  case KEYEV_Down: return pFuncDown ? (rTarget.*pFuncDown)(key) : false;
338  case KEYEV_Up: return pFuncUp ? (rTarget.*pFuncUp)(key) : false;
339  case KEYEV_Pressed: return pFuncPressed ? (rTarget.*pFuncPressed)(key) : false;
340  case KEYEV_Moved: return pFuncMoved ? (rTarget.*pFuncMoved)(key) : false;
341  default: return false;
342  }
343  }
344 
345  virtual bool CheckCondition() { return true; }
346 
347 public:
348  C4KeyCBPassKey(TargetClass &rTarget, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
349  : rTarget(rTarget), pFuncDown(pFuncDown), pFuncUp(pFuncUp), pFuncPressed(pFuncPressed), pFuncMoved(pFuncMoved) {}
350 };
351 
352 // parameterized callback interface
353 template <class TargetClass, class ParameterType> class C4KeyCBEx : public C4KeyboardCallbackInterface
354 {
355 public:
356  typedef bool(TargetClass::*CallbackFunc)(ParameterType par);
357 
358 protected:
359  TargetClass &rTarget;
361  ParameterType par;
362 
363 protected:
364  bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
365  {
366  if (!CheckCondition()) return false;
367  switch (eEv)
368  {
369  case KEYEV_Down: return pFuncDown ? (rTarget.*pFuncDown)(par) : false;
370  case KEYEV_Up: return pFuncUp ? (rTarget.*pFuncUp)(par) : false;
371  case KEYEV_Pressed: return pFuncPressed ? (rTarget.*pFuncPressed)(par) : false;
372  case KEYEV_Moved: return pFuncMoved ? (rTarget.*pFuncMoved)(par) : false;
373  default: return false;
374  }
375  }
376 
377  virtual bool CheckCondition() { return true; }
378 
379 public:
380  C4KeyCBEx(TargetClass &rTarget, const ParameterType &par, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
381  : rTarget(rTarget), pFuncDown(pFuncDown), pFuncUp(pFuncUp), pFuncPressed(pFuncPressed), pFuncMoved(pFuncMoved), par(par) {}
382 };
383 
384 template <class TargetClass, class ParameterType> class C4KeyCBExPassKey : public C4KeyboardCallbackInterface
385 {
386 public:
387  typedef bool(TargetClass::*CallbackFunc)(const C4KeyCodeEx &key, const ParameterType &par);
388 
389 protected:
390  TargetClass &rTarget;
392  ParameterType par;
393 
394 protected:
395  bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
396  {
397  if (!CheckCondition()) return false;
398  switch (eEv)
399  {
400  case KEYEV_Down: return pFuncDown ? (rTarget.*pFuncDown)(key, par) : false;
401  case KEYEV_Up: return pFuncUp ? (rTarget.*pFuncUp)(key, par) : false;
402  case KEYEV_Pressed: return pFuncPressed ? (rTarget.*pFuncPressed)(key, par) : false;
403  case KEYEV_Moved: return pFuncMoved ? (rTarget.*pFuncMoved)(key, par) : false;
404  default: return false;
405  }
406  }
407 
408  virtual bool CheckCondition() { return true; }
409 
410 public:
411  C4KeyCBExPassKey(TargetClass &rTarget, const ParameterType &par, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
412  : rTarget(rTarget), pFuncDown(pFuncDown), pFuncUp(pFuncUp), pFuncPressed(pFuncPressed), pFuncMoved(pFuncMoved), par(par) {}
413 };
414 
415 // one mapped keyboard entry
417 {
418 public:
419  typedef std::vector<C4KeyCodeEx> CodeList;
420 private:
421  CodeList Codes, DefaultCodes; // keyboard scancodes of OS plus shift state
422  C4KeyScope Scope; // scope in which key is processed
423  StdStrBuf Name; // custom key name; used for association in config files
424  typedef std::vector<C4KeyboardCallbackInterface *> CBVec;
425  unsigned int uiPriority; // key priority: If multiple keys of same code are defined, high prio overwrites low prio keys
426  bool is_down; // down-callbacks have been executed but up-callbacks have not (not compiled)
427 
428 public:
429  CBVec vecCallbacks; // a list of all callbacks assigned to that key
430 
431  enum Priority
432  {
433  PRIO_None = 0u,
434  PRIO_Base = 1u,
435  PRIO_Dlg = 2u,
436  PRIO_Ctrl = 3u, // controls have higher priority than dialogs in GUI
437  PRIO_CtrlOverride = 4u, // dialog handlings of keys that overwrite regular control handlings
438  PRIO_FocusCtrl = 5u, // controls override special dialog handling keys (e.g., RenameEdit)
439  PRIO_Context = 6u, // context menus above controls
440  PRIO_PlrControl = 7u, // player controls overwrite any other controls
441  PRIO_MoreThanMax = 100u // must be larger than otherwise largest used priority
442  };
443 
444 protected:
445  int iRef;
446  C4CustomKey(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority = PRIO_Base); // ctor for default key
447  C4CustomKey(CodeList rDefCodes, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority = PRIO_Base); // ctor for default key with multiple possible keys assigned
448  friend class C4Game;
449 
450 public:
451  C4CustomKey(const C4CustomKey &rCpy, bool fCopyCallbacks);
452  virtual ~C4CustomKey(); // dtor
453 
454  inline void Ref() { ++iRef; }
455  inline void Deref() { if (!--iRef) delete this; }
456 
457  const CodeList &GetCodes() const { return Codes.size() ? Codes : DefaultCodes; } // return assigned codes; default if no custom has been assigned
458  const StdStrBuf &GetName() const { return Name; }
459  C4KeyScope GetScope() const { return Scope; }
460  unsigned int GetPriority() const { return uiPriority; }
461  bool IsCodeMatched(const C4KeyCodeEx &key) const;
462 
463  void Update(const C4CustomKey *pByKey); // merge given key into this
464  bool Execute(C4KeyEventType eEv, C4KeyCodeEx key);
465 
466  bool IsDown() const { return is_down; }
467 
468  void KillCallbacks(const C4CustomKey *pOfKey); // remove any callbacks that were created by given key
469 
470  void CompileFunc(StdCompiler *pComp);
471 };
472 
473 // a key that auto-registers itself into main game keyboard input class and does dereg when deleted
474 class C4KeyBinding : protected C4CustomKey
475 {
476 public:
477  C4KeyBinding(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority = PRIO_Base); // ctor for default key
478  C4KeyBinding(const CodeList &rDefCodes, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority = PRIO_Base); // ctor for default key
479  ~C4KeyBinding() override;
480 };
481 
482 // main keyboard mapping class
484 {
485 private:
486  // comparison fn for map
487  struct szLess
488  {
489  bool operator()(const char *p, const char *q) const { return p && q && (strcmp(p,q)<0); }
490  };
491 
492  typedef std::multimap<C4KeyCode, C4CustomKey *> KeyCodeMap;
493  typedef std::map<const char *, C4CustomKey *, szLess> KeyNameMap;
494  // mapping of all keys by code and name
495  KeyCodeMap KeysByCode;
496  KeyNameMap KeysByName;
497  C4KeyEventData LastKeyExtraData;
498 
499 public:
500  static bool IsValid; // global var to fix any deinitialization orders of key map and static keys
501 
502  C4KeyboardInput() { IsValid = true; }
503  ~C4KeyboardInput() { Clear(); IsValid = false; }
504 
505  void Clear(); // empty keyboard maps
506 
507 private:
508  // assign keycodes changed for a key: Update codemap
509  void UpdateKeyCodes(C4CustomKey *pKey, const C4CustomKey::CodeList &rOldCodes, const C4CustomKey::CodeList &rNewCodes);
510 
511 public:
512  void RegisterKey(C4CustomKey *pRegKey); // register key into code and name maps, or update specific key
513  void UnregisterKey(const StdStrBuf &rsName); // remove key from all maps
514  void UnregisterKeyBinding(C4CustomKey *pKey); // just remove callbacks from a key
515 
516  bool DoInput(const C4KeyCodeEx &InKey, C4KeyEventType InEvent, DWORD InScope, int32_t iStrength);
517 
518  void CompileFunc(StdCompiler *pComp);
519  bool LoadCustomConfig(); // load keyboard customization file
520 
521  C4CustomKey *GetKeyByName(const char *szKeyName);
522  StdStrBuf GetKeyCodeNameByKeyName(const char *szKeyName, bool fShort = false, int32_t iIndex = 0);
523  const C4KeyEventData &GetLastKeyExtraData() const { return LastKeyExtraData; }
524  void SetLastKeyExtraData(const C4KeyEventData &data) { LastKeyExtraData=data; }
525 };
526 
527 // keyboardinput-initializer-helper
529 
530 #endif // INC_C4KeyboardInput
531 
virtual bool CheckCondition()
TargetClass & rTarget
void Any(T &keys)
CallbackFunc pFuncUp
C4KeyScope GetScope() const
ParameterType par
~C4KeyBinding() override
C4KeyCodeEx(C4KeyCode Key=KEY_Default, C4KeyShiftState Shift=KEYS_None, bool fIsRepeated=false, int32_t deviceId=-1)
void Up(T &keys)
static C4KeyShiftState String2KeyShift(const StdStrBuf &sName)
CallbackFunc pFuncDown
uint8_t Key_GetMouse(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_ButtonLeftShoulder
static C4KeyCode String2KeyCode(const StdStrBuf &sName)
bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
CallbackFunc pFuncMoved
void Down(T &keys)
const C4KeyCode KEY_CONTROLLER_AxisTriggerLeft
C4KeyCBExPassKey(TargetClass &rTarget, const ParameterType &par, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
const C4KeyCode KEY_MOUSE_Mask
const C4KeyCode KEY_MOUSE_ButtonX1
const C4KeyCode KEY_CONTROLLER_ButtonY
C4CustomKey(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority=PRIO_Base)
bool(TargetClass::* CallbackFunc)(const C4KeyCodeEx &key)
C4CustomKey * GetKeyByName(const char *szKeyName)
const C4KeyCode KEY_CONTROLLER_AxisMax
void Cancel(T &keys)
CallbackFunc pFuncDown
const C4KeyCode KEY_CONTROLLER_AxisMin
C4KeyEventData()=default
const C4KeyCode KEY_CONTROLLER_ButtonRightStick
CallbackFunc pFuncDown
C4KeyShiftState
const C4KeyCode KEY_CONTROLLER_ButtonStart
const C4KeyCode KEY_CONTROLLER_ButtonB
void CompileFunc(StdCompiler *pComp)
ParameterType par
void Update(const C4CustomKey *pByKey)
CallbackFunc pFuncMoved
uint8_t KEY_CONTROLLER_Button(uint8_t idx)
bool(TargetClass::* CallbackFunc)()
const C4KeyCode KEY_MOUSE_Button1
const C4KeyCode KEY_MOUSE_Wheel1Up
const C4KeyCode KEY_CONTROLLER_ButtonDpadDown
bool Key_IsGamepadAxisHigh(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_AxisLeftXRight
C4KeyCode KEY_Mouse(uint8_t mouse_id, uint8_t mouseevent)
C4KeyCB(TargetClass &rTarget, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
bool(TargetClass::* CallbackFunc)(const C4KeyCodeEx &key, const ParameterType &par)
static StdStrBuf KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort)
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
std::vector< C4KeyCodeEx > CodeList
CallbackFunc pFuncMoved
StdStrBuf GetKeyCodeNameByKeyName(const char *szKeyName, bool fShort=false, int32_t iIndex=0)
uint8_t Key_GetMouseEvent(C4KeyCode key)
virtual bool CheckCondition()
const C4KeyCode KEY_CONTROLLER_ButtonBack
C4KeyCBPassKey(TargetClass &rTarget, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
CallbackFunc pFuncPressed
const C4KeyCode KEY_MOUSE_ButtonMaxDouble
const C4KeyCode KEY_CONTROLLER_ButtonA
bool operator==(const C4KeyCodeEx &v2) const
const C4KeyCode KEY_CONTROLLER_ButtonRightShoulder
bool Key_IsGamepadButton(C4KeyCode key)
const StdStrBuf & GetName() const
bool IsRepeated() const
bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
const C4KeyCode KEY_CONTROLLER_AxisRightXLeft
virtual bool CheckCondition()
const C4KeyCode KEY_MOUSE_ButtonLeftDouble
const C4KeyCode KEY_Default
CallbackFunc pFuncMoved
CallbackFunc pFuncPressed
int32_t deviceId
const C4KeyCode KEY_MOUSE_ButtonX1Double
CallbackFunc pFuncUp
void SetLastKeyExtraData(const C4KeyEventData &data)
bool Key_IsMouse(C4KeyCode key)
uint8_t Key_GetGamepad(C4KeyCode key)
bool Key_IsGamepad(C4KeyCode key)
C4KeyCode KEY_Gamepad(uint8_t idButton)
C4KeyCBEx(TargetClass &rTarget, const ParameterType &par, CallbackFunc pFuncDown, CallbackFunc pFuncUp=nullptr, CallbackFunc pFuncPressed=nullptr, CallbackFunc pFuncMoved=nullptr)
const C4KeyCode KEY_CONTROLLER_ButtonMax
const C4KeyCode KEY_CONTROLLER_AxisLeftXLeft
const C4KeyCode KEY_CONTROLLER_ButtonMin
bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
CallbackFunc pFuncPressed
const C4KeyCode KEY_CONTROLLER_ButtonLeftStick
const C4KeyCode KEY_MOUSE_ButtonX2
C4KeyCode Key
const C4KeyCode KEY_MOUSE_ButtonX2Double
Definition: C4Game.h:32
const C4KeyCode KEY_MOUSE_Move
uint8_t KEY_CONTROLLER_Axis(uint8_t idx, bool fMax)
void Right(T &keys)
const C4KeyCode KEY_Undefined
static bool IsValid
const C4KeyCode KEY_MOUSE_ButtonRightDouble
const C4KeyCode KEY_MOUSE_Button1Double
C4KeyEventType
void Ok(T &keys)
C4KeyBinding(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority=PRIO_Base)
bool(TargetClass::* CallbackFunc)(ParameterType par)
virtual bool CheckCondition()
uint8_t Key_GetGamepadEvent(C4KeyCode key)
bool IsCodeMatched(const C4KeyCodeEx &key) const
C4KeyScope
bool IsOriginalKey(const class C4CustomKey *pCheckKey) const
bool DoInput(const C4KeyCodeEx &InKey, C4KeyEventType InEvent, DWORD InScope, int32_t iStrength)
const C4KeyCode KEY_CONTROLLER_AxisRightYDown
bool Key_IsGamepadAxis(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_AxisRightXRight
StdStrBuf ToString(bool fHumanReadable, bool fShort) const
void KillCallbacks(const C4CustomKey *pOfKey)
unsigned int GetPriority() const
const C4KeyCode KEY_Any
const C4KeyCode KEY_CONTROLLER_ButtonDpadLeft
const C4KeyCode KEY_CONTROLLER_ButtonGuide
virtual ~C4KeyboardCallbackInterface()=default
const C4KeyCode KEY_MOUSE_ButtonMiddleDouble
const CodeList & GetCodes() const
const C4KeyCode KEY_CONTROLLER_AxisRightYUp
virtual ~C4CustomKey()
const C4KeyCode KEY_MOUSE_ButtonRight
void UnregisterKey(const StdStrBuf &rsName)
CallbackFunc pFuncUp
bool operator<(const C4KeyCodeEx &v2) const
TargetClass & rTarget
bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv) override
TargetClass & rTarget
void RegisterKey(C4CustomKey *pRegKey)
void CompileFunc(StdCompiler *pComp)
CallbackFunc pFuncPressed
void Left(T &keys)
const C4KeyCode KEY_CONTROLLER_AxisLeftYUp
const C4KeyCode KEY_CONTROLLER_ButtonDpadUp
uint32_t DWORD
const C4KeyCode KEY_MOUSE_ButtonLeft
C4KeyboardInput & C4KeyboardInput_Init()
void CompileFunc(StdCompiler *pComp, StdStrBuf *pOutBuf=nullptr)
const C4KeyCode KEY_CONTROLLER_Mask
virtual bool OnKeyEvent(const C4KeyCodeEx &key, C4KeyEventType eEv)=0
TargetClass & rTarget
const C4KeyCode KEY_CONTROLLER_ButtonX
const C4KeyCode KEY_CONTROLLER_AnyButton
const C4KeyCode KEY_CONTROLLER_ButtonDpadRight
CallbackFunc pFuncUp
bool Execute(C4KeyEventType eEv, C4KeyCodeEx key)
bool IsDown() const
unsigned long C4KeyCode
const C4KeyCode KEY_MOUSE_ButtonMax
const C4KeyCode KEY_CONTROLLER_AxisLeftYDown
void UnregisterKeyBinding(C4CustomKey *pKey)
CallbackFunc pFuncDown
class C4CustomKey * pOriginalKey
uint8_t Key_GetGamepadAxisIndex(C4KeyCode key)
const C4KeyCode KEY_MOUSE_ButtonMiddle
const C4KeyCode KEY_MOUSE_Wheel1Down
const C4KeyCode KEY_CONTROLLER_AxisTriggerRight
const C4KeyEventData & GetLastKeyExtraData() const
static StdStrBuf KeyShift2String(C4KeyShiftState eShift)
uint8_t Key_GetGamepadButtonIndex(C4KeyCode key)
void CompileFunc(StdCompiler *pComp)