OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4KeyCodeEx Struct Reference

#include <C4KeyboardInput.h>

Public Member Functions

StdStrBuf ToString (bool fHumanReadable, bool fShort) const
 
bool operator< (const C4KeyCodeEx &v2) const
 
bool operator== (const C4KeyCodeEx &v2) const
 
void CompileFunc (StdCompiler *pComp, StdStrBuf *pOutBuf=nullptr)
 
 C4KeyCodeEx (C4KeyCode Key=KEY_Default, C4KeyShiftState Shift=KEYS_None, bool fIsRepeated=false, int32_t deviceId=-1)
 
bool IsRepeated () const
 
void FixShiftKeys ()
 

Static Public Member Functions

static C4KeyShiftState String2KeyShift (const StdStrBuf &sName)
 
static C4KeyCode String2KeyCode (const StdStrBuf &sName)
 
static StdStrBuf KeyCode2String (C4KeyCode wCode, bool fHumanReadable, bool fShort)
 
static StdStrBuf KeyShift2String (C4KeyShiftState eShift)
 

Public Attributes

C4KeyCode Key
 
DWORD dwShift
 
int32_t deviceId
 
bool fRepeated
 

Detailed Description

Definition at line 200 of file C4KeyboardInput.h.

Constructor & Destructor Documentation

C4KeyCodeEx::C4KeyCodeEx ( C4KeyCode  Key = KEY_Default,
C4KeyShiftState  Shift = KEYS_None,
bool  fIsRepeated = false,
int32_t  deviceId = -1 
)

Definition at line 189 of file C4KeyboardInput.cpp.

190 : Key(key), dwShift(Shift), fRepeated(fIsRepeated), deviceId(deviceId)
191 {
192 }
int32_t deviceId
C4KeyCode Key

Member Function Documentation

void C4KeyCodeEx::CompileFunc ( StdCompiler pComp,
StdStrBuf pOutBuf = nullptr 
)

Definition at line 481 of file C4KeyboardInput.cpp.

References dwShift, StdCompiler::excCorrupt(), FormatString(), StdStrBuf::getData(), StdStrBuf::getLength(), StdCompiler::isDeserializer(), Key, KEY_Default, KEY_Undefined, KeyCode2String(), KEYS_First, KEYS_Max, KEYS_Undefined, KeyShift2String(), mkDecompileAdapt(), mkParAdapt(), StdCompiler::NoSeparator(), StdCompiler::RCT_Idtf, StdCompiler::SEP_DOLLAR, StdCompiler::SEP_PLUS, StdCompiler::Separator(), String2KeyCode(), String2KeyShift(), StdStrBuf::Take(), and StdCompiler::Value().

482 {
483  if (pComp->isDeserializer())
484  {
485  // reading from file
486  StdStrBuf sCode;
487  bool is_scan_code;
488  // read shifts
489  DWORD dwSetShift = 0;
490  for (;;)
491  {
492  is_scan_code = pComp->Separator(StdCompiler::SEP_DOLLAR);
493  if (!is_scan_code) pComp->NoSeparator();
494  pComp->Value(mkParAdapt(sCode, StdCompiler::RCT_Idtf));
495  if (is_scan_code) // scan codes start with $. Reassamble the two tokens that were split by StdCompiler
496  {
497  sCode.Take(FormatString("$%s", sCode.getData()));
498  break;
499  }
500  if (!pComp->Separator(StdCompiler::SEP_PLUS)) break; // no more separator: Parse this as keyboard code
501  // try to convert to shift state
502  C4KeyShiftState eAddState = String2KeyShift(sCode);
503  if (eAddState == KEYS_Undefined)
504  pComp->excCorrupt("undefined key shift state: %s", sCode.getData());
505  dwSetShift |= eAddState;
506  }
507  // any code given? Otherwise, keep default
508  if (sCode.getLength())
509  {
510  // last section: convert to key code
511  C4KeyCode eCode = String2KeyCode(sCode);
512  if (eCode == KEY_Undefined)
513  {
514  if (pOutBuf)
515  {
516  // unknown key, but an output buffer for unknown keys was provided. No failure; caller might resolve key.
517  eCode = KEY_Default;
518  }
519  else
520  {
521  pComp->excCorrupt("undefined key code: %s", sCode.getData());
522  }
523  }
524  dwShift = dwSetShift;
525  Key = eCode;
526  if (pOutBuf) pOutBuf->Take(std::move(sCode));
527  }
528  }
529  else
530  {
531  // write shift states
532  for (DWORD dwShiftCheck = KEYS_First; dwShiftCheck <= KEYS_Max; dwShiftCheck <<= 1)
533  if (dwShiftCheck & dwShift)
534  {
535  pComp->Value(mkDecompileAdapt(KeyShift2String((C4KeyShiftState) dwShiftCheck)));
537  }
538  // write key
539  pComp->Value(mkDecompileAdapt(KeyCode2String(Key, false, false)));
540  }
541 }
const char * getData() const
Definition: StdBuf.h:442
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
virtual void NoSeparator()
Definition: StdCompiler.h:120
static C4KeyShiftState String2KeyShift(const StdStrBuf &sName)
static C4KeyCode String2KeyCode(const StdStrBuf &sName)
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
C4KeyShiftState
static StdStrBuf KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort)
const C4KeyCode KEY_Default
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:153
void Take(char *pnData)
Definition: StdBuf.h:457
void Value(const T &rStruct)
Definition: StdCompiler.h:161
C4KeyCode Key
virtual bool isDeserializer()
Definition: StdCompiler.h:53
const C4KeyCode KEY_Undefined
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
size_t getLength() const
Definition: StdBuf.h:445
uint32_t DWORD
unsigned long C4KeyCode
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
static StdStrBuf KeyShift2String(C4KeyShiftState eShift)

Here is the call graph for this function:

void C4KeyCodeEx::FixShiftKeys ( )

Definition at line 194 of file C4KeyboardInput.cpp.

References dwShift, Key, KEYS_Control, and KEYS_Shift.

Referenced by C4Game::DoKeyboardInput().

195 {
196  // reduce stuff like Ctrl+RightCtrl to simply RightCtrl
197  if ((dwShift & KEYS_Control) && (Key == K_CONTROL_L || Key == K_CONTROL_R)) dwShift &= ~KEYS_Control;
198  if ((dwShift & KEYS_Shift) && (Key == K_SHIFT_L || Key == K_SHIFT_R)) dwShift &= ~KEYS_Shift;
199 }
C4KeyCode Key

Here is the caller graph for this function:

bool C4KeyCodeEx::IsRepeated ( ) const
inline

Definition at line 233 of file C4KeyboardInput.h.

References fRepeated.

233 { return fRepeated; }
StdStrBuf C4KeyCodeEx::KeyCode2String ( C4KeyCode  wCode,
bool  fHumanReadable,
bool  fShort 
)
static

Definition at line 326 of file C4KeyboardInput.cpp.

References StdStrBuf::Copy(), StdStrBuf::Format(), FormatString(), StdStrBuf::getLength(), KEY_CONTROLLER_AnyButton, KEY_CONTROLLER_AxisLeftXLeft, KEY_CONTROLLER_AxisLeftXRight, KEY_CONTROLLER_AxisLeftYDown, KEY_CONTROLLER_AxisLeftYUp, KEY_CONTROLLER_AxisRightXLeft, KEY_CONTROLLER_AxisRightXRight, KEY_CONTROLLER_AxisRightYDown, KEY_CONTROLLER_AxisRightYUp, KEY_CONTROLLER_AxisTriggerLeft, KEY_CONTROLLER_AxisTriggerRight, KEY_CONTROLLER_ButtonA, KEY_CONTROLLER_ButtonB, KEY_CONTROLLER_ButtonBack, KEY_CONTROLLER_ButtonDpadDown, KEY_CONTROLLER_ButtonDpadLeft, KEY_CONTROLLER_ButtonDpadRight, KEY_CONTROLLER_ButtonDpadUp, KEY_CONTROLLER_ButtonGuide, KEY_CONTROLLER_ButtonLeftShoulder, KEY_CONTROLLER_ButtonLeftStick, KEY_CONTROLLER_ButtonRightShoulder, KEY_CONTROLLER_ButtonRightStick, KEY_CONTROLLER_ButtonStart, KEY_CONTROLLER_ButtonX, KEY_CONTROLLER_ButtonY, Key_GetGamepadEvent(), Key_GetMouse(), Key_GetMouseEvent(), Key_IsGamepad(), Key_IsMouse(), KEY_MOUSE_Button1, KEY_MOUSE_Button1Double, KEY_MOUSE_ButtonLeft, KEY_MOUSE_ButtonLeftDouble, KEY_MOUSE_ButtonMiddle, KEY_MOUSE_ButtonMiddleDouble, KEY_MOUSE_ButtonRight, KEY_MOUSE_ButtonRightDouble, KEY_MOUSE_ButtonX1, KEY_MOUSE_ButtonX1Double, KEY_MOUSE_ButtonX2, KEY_MOUSE_ButtonX2Double, KEY_MOUSE_Move, KEY_MOUSE_Wheel1Down, KEY_MOUSE_Wheel1Up, KeyCodeMap, KeycodeToString(), C4KeyCodeMapEntry::szName, C4KeyCodeMapEntry::szShortName, and C4KeyCodeMapEntry::wCode.

Referenced by CompileFunc(), and ToString().

327 {
328  // Gamepad keys
329  if (Key_IsGamepad(wCode))
330  {
331  if (fHumanReadable)
332  {
333  switch (Key_GetGamepadEvent(wCode))
334  {
335  case KEY_CONTROLLER_ButtonA : return StdStrBuf("{{@Ico:A}}");
336  case KEY_CONTROLLER_ButtonB : return StdStrBuf("{{@Ico:B}}");
337  case KEY_CONTROLLER_ButtonX : return StdStrBuf("{{@Ico:X}}");
338  case KEY_CONTROLLER_ButtonY : return StdStrBuf("{{@Ico:Y}}");
339  case KEY_CONTROLLER_ButtonBack : return StdStrBuf("{{@Ico:Back}}");
340  case KEY_CONTROLLER_ButtonGuide : return StdStrBuf("Guide");
341  case KEY_CONTROLLER_ButtonStart : return StdStrBuf("{{@Ico:Start}}");
342  case KEY_CONTROLLER_ButtonLeftStick : return StdStrBuf("{{@Ico:LeftStick}}");
343  case KEY_CONTROLLER_ButtonRightStick : return StdStrBuf("{{@Ico:RightStick}}");
344  case KEY_CONTROLLER_ButtonLeftShoulder : return StdStrBuf("{{@Ico:LeftShoulder}}");
345  case KEY_CONTROLLER_ButtonRightShoulder : return StdStrBuf("{{@Ico:RightShoulder}}");
346  case KEY_CONTROLLER_ButtonDpadUp : return StdStrBuf("{{@Ico:DpadUp}}");
347  case KEY_CONTROLLER_ButtonDpadDown : return StdStrBuf("{{@Ico:DpadDown}}");
348  case KEY_CONTROLLER_ButtonDpadLeft : return StdStrBuf("{{@Ico:DpadLeft}}");
349  case KEY_CONTROLLER_ButtonDpadRight : return StdStrBuf("{{@Ico:DpadRight}}");
350  case KEY_CONTROLLER_AnyButton : return StdStrBuf("Any Button");
351  case KEY_CONTROLLER_AxisLeftXLeft : return StdStrBuf("{{@Ico:LeftStick}} Left");
352  case KEY_CONTROLLER_AxisLeftXRight : return StdStrBuf("{{@Ico:LeftStick}} Right");
353  case KEY_CONTROLLER_AxisLeftYUp : return StdStrBuf("{{@Ico:LeftStick}} Up");
354  case KEY_CONTROLLER_AxisLeftYDown : return StdStrBuf("{{@Ico:LeftStick}} Down");
355  case KEY_CONTROLLER_AxisRightXLeft : return StdStrBuf("{{@Ico:RightStick}} Left");
356  case KEY_CONTROLLER_AxisRightXRight : return StdStrBuf("{{@Ico:RightStick}} Right");
357  case KEY_CONTROLLER_AxisRightYUp : return StdStrBuf("{{@Ico:RightStick}} Up");
358  case KEY_CONTROLLER_AxisRightYDown : return StdStrBuf("{{@Ico:RightStick}} Down");
359  case KEY_CONTROLLER_AxisTriggerLeft : return StdStrBuf("{{@Ico:LeftTrigger}}");
360  case KEY_CONTROLLER_AxisTriggerRight : return StdStrBuf("{{@Ico:RightTrigger}}");
361  }
362  }
363  else
364  {
365  // A linear search in our small map is probably fast enough.
366  auto it = std::find_if(controllercodes.begin(), controllercodes.end(), [wCode](const auto &p)
367  {
368  return p.second == Key_GetGamepadEvent(wCode);
369  });
370  if (it != controllercodes.end())
371  return FormatString("Controller%s", it->first.c_str());
372  }
373  return StdStrBuf("Unknown");
374  }
375 
376  // Mouse keys
377  if (Key_IsMouse(wCode))
378  {
379  int mouse_id = Key_GetMouse(wCode);
380  int mouse_event = Key_GetMouseEvent(wCode);
381  const char *mouse_str = "Mouse";
382  switch (mouse_event)
383  {
384  case KEY_MOUSE_Move: return FormatString("%s%dMove", mouse_str, mouse_id);
385  case KEY_MOUSE_Wheel1Up: return FormatString("%s%dWheel1Up", mouse_str, mouse_id);
386  case KEY_MOUSE_Wheel1Down: return FormatString("%s%dWheel1Down", mouse_str, mouse_id);
387  case KEY_MOUSE_ButtonLeft: return FormatString("%s%dLeft", mouse_str, mouse_id);
388  case KEY_MOUSE_ButtonRight: return FormatString("%s%dRight", mouse_str, mouse_id);
389  case KEY_MOUSE_ButtonMiddle: return FormatString("%s%dMiddle", mouse_str, mouse_id);
390  case KEY_MOUSE_ButtonX1: return FormatString("%s%dX1", mouse_str, mouse_id);
391  case KEY_MOUSE_ButtonX2: return FormatString("%s%dX2", mouse_str, mouse_id);
392  case KEY_MOUSE_ButtonLeftDouble: return FormatString("%s%dLeftDouble", mouse_str, mouse_id);
393  case KEY_MOUSE_ButtonRightDouble: return FormatString("%s%dRightDouble", mouse_str, mouse_id);
394  case KEY_MOUSE_ButtonMiddleDouble:return FormatString("%s%dMiddleDouble", mouse_str, mouse_id);
395  case KEY_MOUSE_ButtonX1Double: return FormatString("%s%dX1Double", mouse_str, mouse_id);
396  case KEY_MOUSE_ButtonX2Double: return FormatString("%s%dX2Double", mouse_str, mouse_id);
397  default:
398  // extended mouse button
399  {
400  uint8_t btn = Key_GetMouseEvent(wCode);
401  if (btn >= KEY_MOUSE_Button1Double)
402  return FormatString("%s%dButton%dDouble", mouse_str, mouse_id, int(btn-KEY_MOUSE_Button1Double));
403  else
404  return FormatString("%s%dButton%d", mouse_str, mouse_id, int(btn-KEY_MOUSE_Button1));
405  }
406  }
407  }
408 
409  // it's a keyboard key
410  if (!fHumanReadable) {
411  // for config files and such: dump scancode
412  return FormatString("$%x", static_cast<unsigned int>(wCode));
413  }
414 #if defined(USE_WIN32_WINDOWS)
415 
416  // Query map
417  const C4KeyCodeMapEntry *pCheck = KeyCodeMap;
418  while (pCheck->szName)
419  if (wCode == pCheck->wCode) return StdStrBuf((pCheck->szShortName && fShort) ? pCheck->szShortName : pCheck->szName); else ++pCheck;
420 
421 // TODO: Works?
422 // StdStrBuf Name; Name.SetLength(1000);
423 // int res = GetKeyNameText(wCode, Name.getMData(), Name.getSize());
424 // if(!res)
425 // // not found: Compose as direct code
426 // return FormatString("\\x%x", (DWORD) wCode);
427 // // Set size
428 // Name.SetLength(res);
429 // return Name;
430 
431  wchar_t buf[100];
432  int len = GetKeyNameText(wCode<<16, buf, 100);
433  if (len > 0) {
434  // buf is nullterminated name
435  return StdStrBuf(buf);
436  }
437 #elif defined (USE_COCOA)
438  // query map
439  const C4KeyCodeMapEntry *pCheck = KeyCodeMap;
440  while (pCheck->szName)
441  if (wCode == pCheck->wCode) return StdStrBuf((pCheck->szShortName && fShort) ? pCheck->szShortName : pCheck->szName); else ++pCheck;
442  // not found: Compose as direct code
443  return FormatString("\\x%x", static_cast<unsigned int>(wCode));
444 #elif defined(USE_SDL_MAINLOOP)
445  StdStrBuf buf;
446  auto name = KeycodeToString(wCode);
447  if (name) buf.Copy(name);
448  if (!buf.getLength()) buf.Format("\\x%lx", wCode);
449  return buf;
450 #endif
451  return FormatString("$%x", static_cast<unsigned int>(wCode));
452 }
uint8_t Key_GetMouse(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_ButtonLeftShoulder
const C4KeyCode KEY_CONTROLLER_AxisTriggerLeft
const C4KeyCode KEY_MOUSE_ButtonX1
const C4KeyCode KEY_CONTROLLER_ButtonY
const char * szShortName
const C4KeyCode KEY_CONTROLLER_ButtonRightStick
const C4KeyCode KEY_CONTROLLER_ButtonStart
const C4KeyCode KEY_CONTROLLER_ButtonB
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
const C4KeyCode KEY_MOUSE_Button1
const C4KeyCode KEY_MOUSE_Wheel1Up
const C4KeyCode KEY_CONTROLLER_ButtonDpadDown
const C4KeyCode KEY_CONTROLLER_AxisLeftXRight
const char * KeycodeToString(C4KeyCode code)
Definition: C4AppSDL.cpp:248
const C4KeyCodeMapEntry KeyCodeMap[]
uint8_t Key_GetMouseEvent(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_ButtonBack
const C4KeyCode KEY_CONTROLLER_ButtonA
const C4KeyCode KEY_CONTROLLER_ButtonRightShoulder
const C4KeyCode KEY_CONTROLLER_AxisRightXLeft
const C4KeyCode KEY_MOUSE_ButtonLeftDouble
const C4KeyCode KEY_MOUSE_ButtonX1Double
bool Key_IsMouse(C4KeyCode key)
bool Key_IsGamepad(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_AxisLeftXLeft
const C4KeyCode KEY_CONTROLLER_ButtonLeftStick
const C4KeyCode KEY_MOUSE_ButtonX2
const C4KeyCode KEY_MOUSE_ButtonX2Double
const C4KeyCode KEY_MOUSE_Move
const C4KeyCode KEY_MOUSE_ButtonRightDouble
const C4KeyCode KEY_MOUSE_Button1Double
uint8_t Key_GetGamepadEvent(C4KeyCode key)
const C4KeyCode KEY_CONTROLLER_AxisRightYDown
const C4KeyCode KEY_CONTROLLER_AxisRightXRight
const C4KeyCode KEY_CONTROLLER_ButtonDpadLeft
const C4KeyCode KEY_CONTROLLER_ButtonGuide
size_t getLength() const
Definition: StdBuf.h:445
const C4KeyCode KEY_MOUSE_ButtonMiddleDouble
const C4KeyCode KEY_CONTROLLER_AxisRightYUp
const C4KeyCode KEY_MOUSE_ButtonRight
const C4KeyCode KEY_CONTROLLER_AxisLeftYUp
const C4KeyCode KEY_CONTROLLER_ButtonDpadUp
const C4KeyCode KEY_MOUSE_ButtonLeft
void Copy()
Definition: StdBuf.h:467
const C4KeyCode KEY_CONTROLLER_ButtonX
const C4KeyCode KEY_CONTROLLER_AnyButton
const C4KeyCode KEY_CONTROLLER_ButtonDpadRight
const C4KeyCode KEY_CONTROLLER_AxisLeftYDown
const C4KeyCode KEY_MOUSE_ButtonMiddle
const C4KeyCode KEY_MOUSE_Wheel1Down
const C4KeyCode KEY_CONTROLLER_AxisTriggerRight
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

StdStrBuf C4KeyCodeEx::KeyShift2String ( C4KeyShiftState  eShift)
static

Definition at line 60 of file C4KeyboardInput.cpp.

References C4KeyShiftMapEntry::eShift, KeyShiftMap, and C4KeyShiftMapEntry::szName.

Referenced by CompileFunc(), and ToString().

61 {
62  // query map
63  const C4KeyShiftMapEntry *pCheck = KeyShiftMap;
64  while (pCheck->szName)
65  if (eShift == pCheck->eShift) break; else ++pCheck;
66  return StdStrBuf(pCheck->szName);
67 }
const C4KeyShiftMapEntry KeyShiftMap[]
C4KeyShiftState eShift

Here is the caller graph for this function:

bool C4KeyCodeEx::operator< ( const C4KeyCodeEx v2) const
inline

Definition at line 219 of file C4KeyboardInput.h.

References dwShift, and Key.

220  {
221  return Key < v2.Key || (Key == v2.Key && dwShift < v2.dwShift);
222  }
C4KeyCode Key
bool C4KeyCodeEx::operator== ( const C4KeyCodeEx v2) const
inline

Definition at line 224 of file C4KeyboardInput.h.

References dwShift, and Key.

225  {
226  return Key == v2.Key && dwShift == v2.dwShift;
227  }
C4KeyCode Key
C4KeyCode C4KeyCodeEx::String2KeyCode ( const StdStrBuf sName)
static

Definition at line 239 of file C4KeyboardInput.cpp.

References StdStrBuf::getData(), StdStrBuf::getLength(), KEY_Gamepad(), KEY_Mouse(), KEY_MOUSE_Button1, KEY_MOUSE_Button1Double, KEY_MOUSE_ButtonLeft, KEY_MOUSE_ButtonMiddle, KEY_MOUSE_ButtonRight, KEY_MOUSE_ButtonX1, KEY_MOUSE_ButtonX2, KEY_MOUSE_Move, KEY_MOUSE_Wheel1Down, KEY_MOUSE_Wheel1Up, KEY_Undefined, KeyCodeMap, s, SEqualNoCase(), stricmp(), C4KeyCodeMapEntry::szName, and C4KeyCodeMapEntry::wCode.

Referenced by CompileFunc().

240 {
241  // direct key code?
242  if (sName.getLength() > 2)
243  {
244  unsigned int dwRVal;
245  if (sscanf(sName.getData(), R"(\x%x)", &dwRVal) == 1) return dwRVal;
246  // scan code
247  if (*sName.getData() == '$') return GetKeyByScanCode(sName.getData());
248  // direct gamepad code
249  std::regex controller_re(R"/(^Controller(\w+)$)/");
250  std::cmatch matches;
251  if (std::regex_match(sName.getData(), matches, controller_re))
252  {
253  auto keycode_it = controllercodes.find(matches[1].str());
254  if (keycode_it != controllercodes.end())
255  return KEY_Gamepad(keycode_it->second);
256  else
257  return KEY_Undefined;
258 
259  }
260  bool is_mouse_key;
261 #ifdef _WIN32
262  is_mouse_key = !strnicmp(sName.getData(), "Mouse", 5);
263 #else
264  is_mouse_key = !strncasecmp(sName.getData(), "Mouse", 5);
265 #endif
266  if (is_mouse_key)
267  {
268  // skip Mouse/GameMouse
269  const char *key_str = sName.getData()+5;
270  int mouse_id;
271  if (sscanf(key_str, "%d", &mouse_id) == 1)
272  {
273  // skip number
274  while (isdigit(*key_str)) ++key_str;
275  // check for known mouse events (e.g. Mouse1Move or GameMouse1Wheel)
276  if (!stricmp(key_str, "Move")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Move);
277  if (!stricmp(key_str, "Wheel1Up")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Wheel1Up);
278  if (!stricmp(key_str, "Wheel1Down")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Wheel1Down);
279  if (SEqualNoCase(key_str, "Button", 6)) // e.g. Mouse1ButtonLeft or GameMouse1ButtonRightDouble
280  {
281  // check for known mouse button events
282  uint8_t mouseevent_id = 0;
283  key_str += 6;
284  if (SEqualNoCase(key_str, "Left",4)) { mouseevent_id=KEY_MOUSE_ButtonLeft; key_str += 4; }
285  else if (SEqualNoCase(key_str, "Right",5)) { mouseevent_id=KEY_MOUSE_ButtonRight; key_str += 5; }
286  else if (SEqualNoCase(key_str, "Middle",6)) { mouseevent_id=KEY_MOUSE_ButtonMiddle; key_str += 6; }
287  else if (SEqualNoCase(key_str, "X1",2)) { mouseevent_id=KEY_MOUSE_ButtonX1; key_str += 2; }
288  else if (SEqualNoCase(key_str, "X2",2)) { mouseevent_id=KEY_MOUSE_ButtonX2; key_str += 2; }
289  else if (isdigit(*key_str))
290  {
291  // indexed mouse button (e.g. Mouse1Button4 or Mouse1Button4Double)
292  int button_index;
293  if (sscanf(key_str, "%d", &button_index) == 1)
294  {
295  mouseevent_id=static_cast<uint8_t>(KEY_MOUSE_Button1+button_index-1);
296  while (isdigit(*key_str)) ++key_str;
297  }
298  }
299  if (mouseevent_id)
300  {
301  // valid event if finished or followed by "Double"
302  if (!*key_str) return KEY_Mouse(mouse_id-1, mouseevent_id);
303  if (!stricmp(key_str, "Double")) return KEY_Mouse(mouse_id-1, mouseevent_id+(KEY_MOUSE_Button1Double-KEY_MOUSE_Button1));
304  // invalid mouse key...
305  }
306  }
307  }
308  }
309 
310  }
311  // query map
312  const C4KeyCodeMapEntry *pCheck = KeyCodeMap;
313  while (pCheck->szName) {
314  if (SEqualNoCase(sName.getData(), pCheck->szName)) {
315  return(pCheck->wCode);
316  }
317  ++pCheck;
318  }
319 #if defined(USE_SDL_MAINLOOP)
320  SDL_Scancode s = SDL_GetScancodeFromName(sName.getData());
321  if (s != SDL_SCANCODE_UNKNOWN) return s;
322 #endif
323  return KEY_Undefined;
324 }
const char * getData() const
Definition: StdBuf.h:442
const C4KeyCode KEY_MOUSE_ButtonX1
int stricmp(const char *s1, const char *s2)
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
const C4KeyCode KEY_MOUSE_Button1
const C4KeyCode KEY_MOUSE_Wheel1Up
const C4KeyCodeMapEntry KeyCodeMap[]
C4KeyCode KEY_Mouse(uint8_t mouse_id, uint8_t mouseevent)
C4KeyCode KEY_Gamepad(uint8_t idButton)
const C4KeyCode KEY_MOUSE_ButtonX2
const C4KeyCode KEY_MOUSE_Move
const C4KeyCode KEY_Undefined
const C4KeyCode KEY_MOUSE_Button1Double
size_t getLength() const
Definition: StdBuf.h:445
const C4KeyCode KEY_MOUSE_ButtonRight
const C4KeyCode KEY_MOUSE_ButtonLeft
#define s
const C4KeyCode KEY_MOUSE_ButtonMiddle
const C4KeyCode KEY_MOUSE_Wheel1Down

Here is the call graph for this function:

Here is the caller graph for this function:

C4KeyShiftState C4KeyCodeEx::String2KeyShift ( const StdStrBuf sName)
static

Definition at line 51 of file C4KeyboardInput.cpp.

References C4KeyShiftMapEntry::eShift, StdStrBuf::getData(), KeyShiftMap, SEqualNoCase(), and C4KeyShiftMapEntry::szName.

Referenced by CompileFunc().

52 {
53  // query map
54  const C4KeyShiftMapEntry *pCheck = KeyShiftMap;
55  while (pCheck->szName)
56  if (SEqualNoCase(sName.getData(), pCheck->szName)) break; else ++pCheck;
57  return pCheck->eShift;
58 }
const char * getData() const
Definition: StdBuf.h:442
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
const C4KeyShiftMapEntry KeyShiftMap[]
C4KeyShiftState eShift

Here is the call graph for this function:

Here is the caller graph for this function:

StdStrBuf C4KeyCodeEx::ToString ( bool  fHumanReadable,
bool  fShort 
) const

Definition at line 454 of file C4KeyboardInput.cpp.

References StdStrBuf::Append(), StdStrBuf::AppendChar(), StdStrBuf::Clear(), dwShift, StdStrBuf::getLength(), Key, KeyCode2String(), KEYS_First, KEYS_Max, and KeyShift2String().

Referenced by C4KeyboardInput::GetKeyCodeNameByKeyName().

455 {
456  static StdStrBuf sResult;
457  sResult.Clear();
458  // Add shift
459  for (DWORD dwShiftCheck = KEYS_First; dwShiftCheck <= KEYS_Max; dwShiftCheck <<= 1)
460  if (dwShiftCheck & dwShift)
461  {
462  sResult.Append(KeyShift2String((C4KeyShiftState) dwShiftCheck));
463  sResult.AppendChar('+');
464  }
465  // Add key
466  if (sResult.getLength())
467  {
468  sResult.Append(KeyCode2String(Key, fHumanReadable, fShort));
469  return sResult;
470  }
471  else
472  {
473  return KeyCode2String(Key, fHumanReadable, fShort);
474  }
475 }
void Clear()
Definition: StdBuf.h:466
C4KeyShiftState
void AppendChar(char cChar)
Definition: StdBuf.h:588
static StdStrBuf KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort)
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
C4KeyCode Key
size_t getLength() const
Definition: StdBuf.h:445
uint32_t DWORD
static StdStrBuf KeyShift2String(C4KeyShiftState eShift)

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int32_t C4KeyCodeEx::deviceId

Definition at line 205 of file C4KeyboardInput.h.

bool C4KeyCodeEx::fRepeated

Definition at line 209 of file C4KeyboardInput.h.

Referenced by IsRepeated().


The documentation for this struct was generated from the following files: