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