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 207 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 194 of file C4KeyboardInput.cpp.

195 : Key(key), dwShift(Shift), fRepeated(fIsRepeated), deviceId(deviceId)
196 {
197 }
int32_t deviceId
C4KeyCode Key

Member Function Documentation

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

Definition at line 486 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().

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

Here is the call graph for this function:

void C4KeyCodeEx::FixShiftKeys ( )

Definition at line 199 of file C4KeyboardInput.cpp.

References dwShift, Key, KEYS_Control, and KEYS_Shift.

Referenced by C4Game::DoKeyboardInput().

200 {
201  // reduce stuff like Ctrl+RightCtrl to simply RightCtrl
202  if ((dwShift & KEYS_Control) && (Key == K_CONTROL_L || Key == K_CONTROL_R)) dwShift &= ~KEYS_Control;
203  if ((dwShift & KEYS_Shift) && (Key == K_SHIFT_L || Key == K_SHIFT_R)) dwShift &= ~KEYS_Shift;
204 }
C4KeyCode Key

Here is the caller graph for this function:

bool C4KeyCodeEx::IsRepeated ( ) const
inline

Definition at line 240 of file C4KeyboardInput.h.

References fRepeated.

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

Definition at line 331 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().

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

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 65 of file C4KeyboardInput.cpp.

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

Referenced by CompileFunc(), and ToString().

66 {
67  // query map
68  const C4KeyShiftMapEntry *pCheck = KeyShiftMap;
69  while (pCheck->szName)
70  if (eShift == pCheck->eShift) break; else ++pCheck;
71  return StdStrBuf(pCheck->szName);
72 }
const C4KeyShiftMapEntry KeyShiftMap[]
C4KeyShiftState eShift

Here is the caller graph for this function:

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

Definition at line 226 of file C4KeyboardInput.h.

References dwShift, and Key.

227  {
228  return Key < v2.Key || (Key == v2.Key && dwShift < v2.dwShift);
229  }
C4KeyCode Key
bool C4KeyCodeEx::operator== ( const C4KeyCodeEx v2) const
inline

Definition at line 231 of file C4KeyboardInput.h.

References dwShift, and Key.

232  {
233  return Key == v2.Key && dwShift == v2.dwShift;
234  }
C4KeyCode Key
C4KeyCode C4KeyCodeEx::String2KeyCode ( const StdStrBuf sName)
static

Definition at line 244 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().

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

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

Referenced by CompileFunc().

57 {
58  // query map
59  const C4KeyShiftMapEntry *pCheck = KeyShiftMap;
60  while (pCheck->szName)
61  if (SEqualNoCase(sName.getData(), pCheck->szName)) break; else ++pCheck;
62  return pCheck->eShift;
63 }
const char * getData() const
Definition: StdBuf.h:450
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:177
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 459 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().

460 {
461  static StdStrBuf sResult;
462  sResult.Clear();
463  // Add shift
464  for (DWORD dwShiftCheck = KEYS_First; dwShiftCheck <= KEYS_Max; dwShiftCheck <<= 1)
465  if (dwShiftCheck & dwShift)
466  {
467  sResult.Append(KeyShift2String((C4KeyShiftState) dwShiftCheck));
468  sResult.AppendChar('+');
469  }
470  // Add key
471  if (sResult.getLength())
472  {
473  sResult.Append(KeyCode2String(Key, fHumanReadable, fShort));
474  return sResult;
475  }
476  else
477  {
478  return KeyCode2String(Key, fHumanReadable, fShort);
479  }
480 }
void Clear()
Definition: StdBuf.h:474
C4KeyShiftState
void AppendChar(char cChar)
Definition: StdBuf.h:596
static StdStrBuf KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort)
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
C4KeyCode Key
size_t getLength() const
Definition: StdBuf.h:453
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 212 of file C4KeyboardInput.h.

bool C4KeyCodeEx::fRepeated

Definition at line 216 of file C4KeyboardInput.h.

Referenced by IsRepeated().


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