OpenClonk
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, DWORD 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)
 
static C4KeyCodeEx FromC4MC (int8_t mouse_id, int32_t button, DWORD param, bool *is_down=nullptr)
 

Public Attributes

C4KeyCode Key
 
DWORD dwShift
 
int32_t deviceId
 
bool fRepeated
 

Detailed Description

Definition at line 201 of file C4KeyboardInput.h.

Constructor & Destructor Documentation

◆ C4KeyCodeEx()

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

Definition at line 190 of file C4KeyboardInput.cpp.

Referenced by ControllerKeys::Any(), ControllerKeys::Cancel(), ControllerKeys::Down(), ControllerKeys::Left(), ControllerKeys::Ok(), operator==(), ControllerKeys::Right(), and ControllerKeys::Up().

191 : Key(key), dwShift(Shift), fRepeated(fIsRepeated), deviceId(deviceId)
192 {
193 }
int32_t deviceId
C4KeyCode Key
Here is the caller graph for this function:

Member Function Documentation

◆ CompileFunc()

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

Definition at line 519 of file C4KeyboardInput.cpp.

References StdStrBuf::Copy(), 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(), ToString(), and StdCompiler::Value().

Referenced by C4KeyEventData::C4KeyEventData(), C4CustomKey::IsDown(), operator==(), and C4KeyboardInput::~C4KeyboardInput().

520 {
521  if (pComp->isDeserializer())
522  {
523  // reading from file
524  StdStrBuf sCode;
525  bool is_scan_code;
526  // read shifts
527  DWORD dwSetShift = 0;
528  for (;;)
529  {
530  is_scan_code = pComp->Separator(StdCompiler::SEP_DOLLAR);
531  if (!is_scan_code) pComp->NoSeparator();
532  pComp->Value(mkParAdapt(sCode, StdCompiler::RCT_Idtf));
533  if (is_scan_code) // scan codes start with $. Reassamble the two tokens that were split by StdCompiler
534  {
535  sCode.Take(FormatString("$%s", sCode.getData()));
536  break;
537  }
538  if (!pComp->Separator(StdCompiler::SEP_PLUS)) break; // no more separator: Parse this as keyboard code
539  // try to convert to shift state
540  C4KeyShiftState eAddState = String2KeyShift(sCode);
541  if (eAddState == KEYS_Undefined)
542  pComp->excCorrupt("undefined key shift state: %s", sCode.getData());
543  dwSetShift |= eAddState;
544  }
545  // any code given? Otherwise, keep default
546  if (sCode.getLength())
547  {
548  // last section: convert to key code
549  C4KeyCode eCode = String2KeyCode(sCode);
550  if (eCode == KEY_Undefined)
551  {
552  if (pOutBuf)
553  {
554  // unknown key, but an output buffer for unknown keys was provided. No failure; caller might resolve key.
555  eCode = KEY_Default;
556  }
557  else
558  {
559  pComp->excCorrupt("undefined key code: %s", sCode.getData());
560  }
561  }
562  dwShift = dwSetShift;
563  Key = eCode;
564  if (pOutBuf) {
565  // FIXME: This function is used both, to deserialize things like CON_Right and Shift+$12
566  // For CON_…, eCode and dwShift will be zero, and sCode will contain the key name.
567  // For Shift+… sCode will only contain the last token. What is correct here?
568  // Reading C4PlayerControlAssignment::KeyComboItem::CompileFunc suggests that setting not value for parsed combinations may be correct.
569  if (eCode == 0)
570  pOutBuf->Take(std::move(sCode));
571  else
572  pOutBuf->Copy(ToString(false, false));
573  }
574  }
575  }
576  else
577  {
578  // write shift states
579  for (DWORD dwShiftCheck = KEYS_First; dwShiftCheck <= KEYS_Max; dwShiftCheck <<= 1)
580  if (dwShiftCheck & dwShift)
581  {
582  pComp->Value(mkDecompileAdapt(KeyShift2String((C4KeyShiftState) dwShiftCheck)));
584  }
585  // write key
586  pComp->Value(mkDecompileAdapt(KeyCode2String(Key, false, false)));
587  }
588 }
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)
StdStrBuf ToString(bool fHumanReadable, bool fShort) const
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
const char * getData() const
Definition: StdBuf.h:442
C4KeyCode Key
virtual bool isDeserializer()
Definition: StdCompiler.h:53
const C4KeyCode KEY_Undefined
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:476
uint32_t DWORD
void Copy()
Definition: StdBuf.h:467
size_t getLength() const
Definition: StdBuf.h:445
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:
Here is the caller graph for this function:

◆ FixShiftKeys()

void C4KeyCodeEx::FixShiftKeys ( )

Definition at line 233 of file C4KeyboardInput.cpp.

References dwShift, Key, KEY_Undefined, KEYS_Alt, KEYS_Control, and KEYS_Shift.

Referenced by C4Game::DoKeyboardInput(), and IsRepeated().

234 {
235  // reduce stuff like Ctrl+RightCtrl to simply RightCtrl
236  if ((dwShift & KEYS_Alt) && (Key == K_ALT_L || Key == K_ALT_R)) dwShift &= ~KEYS_Alt;
237  if ((dwShift & KEYS_Control) && (Key == K_CONTROL_L || Key == K_CONTROL_R)) dwShift &= ~KEYS_Control;
238  if ((dwShift & KEYS_Shift) && (Key == K_SHIFT_L || Key == K_SHIFT_R)) dwShift &= ~KEYS_Shift;
239 }
C4KeyCode Key
Here is the caller graph for this function:

◆ FromC4MC()

C4KeyCodeEx C4KeyCodeEx::FromC4MC ( int8_t  mouse_id,
int32_t  button,
DWORD  param,
bool *  is_down = nullptr 
)
static

Definition at line 195 of file C4KeyboardInput.cpp.

References C4MC_Button_LeftDouble, C4MC_Button_LeftDown, C4MC_Button_LeftUp, C4MC_Button_MiddleDouble, C4MC_Button_MiddleDown, C4MC_Button_MiddleUp, C4MC_Button_None, C4MC_Button_RightDouble, C4MC_Button_RightDown, C4MC_Button_RightUp, C4MC_Button_Wheel, C4MC_Button_X1Double, C4MC_Button_X1Down, C4MC_Button_X1Up, C4MC_Button_X2Double, C4MC_Button_X2Down, C4MC_Button_X2Up, KEY_Mouse(), 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, KEYS_Alt, KEYS_Control, KEYS_None, and KEYS_Shift.

Referenced by C4PlayerControl::DoMouseInput(), and operator==().

196 {
197  bool dummy;
198  if (!is_down)
199  is_down = &dummy;
200  *is_down = true;
201  C4KeyCode mouseevent_code;
202  int wheel_dir = 0;
203  if (iButton == C4MC_Button_Wheel) wheel_dir = (short)(dwKeyParam >> 16);
204  switch (iButton)
205  {
206  case C4MC_Button_None: mouseevent_code = KEY_MOUSE_Move; break;
207  case C4MC_Button_LeftDown: mouseevent_code = KEY_MOUSE_ButtonLeft; break;
208  case C4MC_Button_LeftUp: mouseevent_code = KEY_MOUSE_ButtonLeft; *is_down = false; break;
209  case C4MC_Button_LeftDouble: mouseevent_code = KEY_MOUSE_ButtonLeftDouble; break;
210  case C4MC_Button_RightDown: mouseevent_code = KEY_MOUSE_ButtonRight; break;
211  case C4MC_Button_RightDouble: mouseevent_code = KEY_MOUSE_ButtonRightDouble; break;
212  case C4MC_Button_RightUp: mouseevent_code = KEY_MOUSE_ButtonRight; *is_down = false; break;
213  case C4MC_Button_MiddleDown: mouseevent_code = KEY_MOUSE_ButtonMiddle; break;
214  case C4MC_Button_MiddleUp: mouseevent_code = KEY_MOUSE_ButtonMiddle; *is_down = false; break;
215  case C4MC_Button_MiddleDouble: mouseevent_code = KEY_MOUSE_ButtonMiddleDouble; break;
216  case C4MC_Button_X1Down: mouseevent_code = KEY_MOUSE_ButtonX1; break;
217  case C4MC_Button_X1Up: mouseevent_code = KEY_MOUSE_ButtonX1; *is_down = false; break;
218  case C4MC_Button_X1Double: mouseevent_code = KEY_MOUSE_ButtonX1Double; break;
219  case C4MC_Button_X2Down: mouseevent_code = KEY_MOUSE_ButtonX2; break;
220  case C4MC_Button_X2Up: mouseevent_code = KEY_MOUSE_ButtonX2; *is_down = false; break;
221  case C4MC_Button_X2Double: mouseevent_code = KEY_MOUSE_ButtonX2Double; break;
222  case C4MC_Button_Wheel:
223  if (!wheel_dir) assert("Attempted to record mouse wheel movement without a direction");
224  mouseevent_code = (wheel_dir > 0) ? KEY_MOUSE_Wheel1Up : KEY_MOUSE_Wheel1Down; break;
225  }
226  C4KeyCodeEx key{KEY_Mouse(mouse_id, mouseevent_code), KEYS_None};
227  if (dwKeyParam & MK_CONTROL) key.dwShift |= KEYS_Control;
228  if (dwKeyParam & MK_SHIFT) key.dwShift |= KEYS_Shift;
229  if (dwKeyParam & MK_ALT) key.dwShift |= KEYS_Alt;
230  return key;
231 }
const int32_t C4MC_Button_MiddleUp
const int32_t C4MC_Button_LeftDown
const C4KeyCode KEY_MOUSE_ButtonX1
const int32_t C4MC_Button_RightUp
const int32_t C4MC_Button_X2Down
const C4KeyCode KEY_MOUSE_Wheel1Up
const int32_t C4MC_Button_MiddleDouble
const int32_t C4MC_Button_X1Double
C4KeyCode KEY_Mouse(uint8_t mouse_id, uint8_t mouseevent)
const int32_t C4MC_Button_LeftDouble
const int32_t C4MC_Button_X2Double
const int32_t C4MC_Button_LeftUp
const int32_t C4MC_Button_X1Up
const C4KeyCode KEY_MOUSE_ButtonLeftDouble
const C4KeyCode KEY_MOUSE_ButtonX1Double
const int32_t C4MC_Button_X1Down
const C4KeyCode KEY_MOUSE_ButtonX2
const int32_t C4MC_Button_RightDown
const C4KeyCode KEY_MOUSE_ButtonX2Double
const C4KeyCode KEY_MOUSE_Move
const int32_t C4MC_Button_Wheel
const C4KeyCode KEY_MOUSE_ButtonRightDouble
const int32_t C4MC_Button_RightDouble
const int32_t C4MC_Button_None
const C4KeyCode KEY_MOUSE_ButtonMiddleDouble
const C4KeyCode KEY_MOUSE_ButtonRight
const int32_t C4MC_Button_MiddleDown
const C4KeyCode KEY_MOUSE_ButtonLeft
unsigned long C4KeyCode
const C4KeyCode KEY_MOUSE_ButtonMiddle
const C4KeyCode KEY_MOUSE_Wheel1Down
const int32_t C4MC_Button_X2Up
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRepeated()

bool C4KeyCodeEx::IsRepeated ( ) const
inline

Definition at line 235 of file C4KeyboardInput.h.

References FixShiftKeys(), and fRepeated.

Referenced by C4PlayerControl::CompileFunc(), and C4ChatInputDialog::OnChatInput().

235 { return fRepeated; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeyCode2String()

StdStrBuf C4KeyCodeEx::KeyCode2String ( C4KeyCode  wCode,
bool  fHumanReadable,
bool  fShort 
)
static

Definition at line 364 of file C4KeyboardInput.cpp.

References 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(), and Key_IsGamepad().

Referenced by C4GUI::Dialog::CharIn(), CompileFunc(), C4GUI::ContextMenu::MouseLeaveEntry(), and ToString().

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

◆ KeyShift2String()

StdStrBuf C4KeyCodeEx::KeyShift2String ( C4KeyShiftState  eShift)
static

Definition at line 61 of file C4KeyboardInput.cpp.

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

Referenced by CompileFunc(), and ToString().

62 {
63  // query map
64  const C4KeyShiftMapEntry *pCheck = KeyShiftMap;
65  while (pCheck->szName)
66  if (eShift == pCheck->eShift) break; else ++pCheck;
67  return StdStrBuf(pCheck->szName);
68 }
const C4KeyShiftMapEntry KeyShiftMap[]
C4KeyShiftState eShift
Here is the caller graph for this function:

◆ operator<()

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

Definition at line 220 of file C4KeyboardInput.h.

References dwShift, and Key.

221  {
222  return Key < v2.Key || (Key == v2.Key && dwShift < v2.dwShift);
223  }
C4KeyCode Key

◆ operator==()

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

Definition at line 225 of file C4KeyboardInput.h.

References C4KeyCodeEx(), CompileFunc(), dwShift, FromC4MC(), Key, KEY_Default, and KEYS_None.

Referenced by C4KeyEventData::C4KeyEventData().

226  {
227  return Key == v2.Key && dwShift == v2.dwShift;
228  }
C4KeyCode Key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ String2KeyCode()

C4KeyCode C4KeyCodeEx::String2KeyCode ( const StdStrBuf sName)
static

Definition at line 279 of file C4KeyboardInput.cpp.

References StdStrBuf::getData(), and StdStrBuf::getLength().

Referenced by CompileFunc().

280 {
281  // direct key code, e.g. "$e" (Backspace)?
282  if (sName.getLength() > 1)
283  {
284  unsigned int dwRVal;
285  if (sscanf(sName.getData(), R"(\x%x)", &dwRVal) == 1) return dwRVal;
286  // scan code
287  if (*sName.getData() == '$') return GetKeyByScanCode(sName.getData());
288  // direct gamepad code
289  std::regex controller_re(R"/(^Controller(\w+)$)/");
290  std::cmatch matches;
291  if (std::regex_match(sName.getData(), matches, controller_re))
292  {
293  auto keycode_it = controllercodes.find(matches[1].str());
294  if (keycode_it != controllercodes.end())
295  return KEY_Gamepad(keycode_it->second);
296  else
297  return KEY_Undefined;
298 
299  }
300  bool is_mouse_key;
301 #ifdef _WIN32
302  is_mouse_key = !strnicmp(sName.getData(), "Mouse", 5);
303 #else
304  is_mouse_key = !strncasecmp(sName.getData(), "Mouse", 5);
305 #endif
306  if (is_mouse_key)
307  {
308  // skip Mouse/GameMouse
309  const char *key_str = sName.getData()+5;
310  int mouse_id;
311  if (sscanf(key_str, "%d", &mouse_id) == 1)
312  {
313  // skip number
314  while (isdigit(*key_str)) ++key_str;
315  // check for known mouse events (e.g. Mouse0Move or GameMouse0Wheel)
316  if (!stricmp(key_str, "Move")) return KEY_Mouse(mouse_id, KEY_MOUSE_Move);
317  if (!stricmp(key_str, "Wheel1Up")) return KEY_Mouse(mouse_id, KEY_MOUSE_Wheel1Up);
318  if (!stricmp(key_str, "Wheel1Down")) return KEY_Mouse(mouse_id, KEY_MOUSE_Wheel1Down);
319  // check for known mouse button events
320  if (SEqualNoCase(key_str, "Button", 6)) // e.g. Mouse0ButtonLeft or GameMouse0ButtonRightDouble (This line is left here to not break anything, the buttons are now named Mouse0Left)
321  key_str += 6;
322  uint8_t mouseevent_id = 0;
323  if (SEqualNoCase(key_str, "Left",4)) { mouseevent_id=KEY_MOUSE_ButtonLeft; key_str += 4; }
324  else if (SEqualNoCase(key_str, "Right",5)) { mouseevent_id=KEY_MOUSE_ButtonRight; key_str += 5; }
325  else if (SEqualNoCase(key_str, "Middle",6)) { mouseevent_id=KEY_MOUSE_ButtonMiddle; key_str += 6; }
326  else if (SEqualNoCase(key_str, "X1",2)) { mouseevent_id=KEY_MOUSE_ButtonX1; key_str += 2; }
327  else if (SEqualNoCase(key_str, "X2",2)) { mouseevent_id=KEY_MOUSE_ButtonX2; key_str += 2; }
328  else if (isdigit(*key_str))
329  {
330  // indexed mouse button (e.g. Mouse0Button4 or Mouse0Button4Double)
331  int button_index;
332  if (sscanf(key_str, "%d", &button_index) == 1)
333  {
334  mouseevent_id=static_cast<uint8_t>(KEY_MOUSE_Button1+button_index);
335  while (isdigit(*key_str)) ++key_str;
336  }
337  }
338  if (mouseevent_id)
339  {
340  // valid event if finished or followed by "Double"
341  if (!*key_str) return KEY_Mouse(mouse_id, mouseevent_id);
342  if (!stricmp(key_str, "Double")) return KEY_Mouse(mouse_id, mouseevent_id+(KEY_MOUSE_Button1Double-KEY_MOUSE_Button1));
343  // invalid mouse key...
344  }
345  }
346  }
347 
348  }
349  // query map
350  const C4KeyCodeMapEntry *pCheck = KeyCodeMap;
351  while (pCheck->szName) {
352  if (SEqualNoCase(sName.getData(), pCheck->szName)) {
353  return(pCheck->wCode);
354  }
355  ++pCheck;
356  }
357 #if defined(USE_SDL_MAINLOOP)
358  SDL_Scancode s = SDL_GetScancodeFromName(sName.getData());
359  if (s != SDL_SCANCODE_UNKNOWN) return s;
360 #endif
361  return KEY_Undefined;
362 }
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 char * getData() const
Definition: StdBuf.h:442
const C4KeyCode KEY_MOUSE_ButtonX2
const C4KeyCode KEY_MOUSE_Move
const C4KeyCode KEY_Undefined
const C4KeyCode KEY_MOUSE_Button1Double
const C4KeyCode KEY_MOUSE_ButtonRight
const C4KeyCode KEY_MOUSE_ButtonLeft
size_t getLength() const
Definition: StdBuf.h:445
#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:

◆ String2KeyShift()

C4KeyShiftState C4KeyCodeEx::String2KeyShift ( const StdStrBuf sName)
static

Definition at line 52 of file C4KeyboardInput.cpp.

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

Referenced by CompileFunc().

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

◆ ToString()

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

Definition at line 492 of file C4KeyboardInput.cpp.

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

Referenced by CompileFunc(), and C4KeyboardInput::GetKeyCodeNameByKeyName().

493 {
494  static StdStrBuf sResult;
495  sResult.Clear();
496  // Add shift
497  for (DWORD dwShiftCheck = KEYS_First; dwShiftCheck <= KEYS_Max; dwShiftCheck <<= 1)
498  if (dwShiftCheck & dwShift)
499  {
500  sResult.Append(KeyShift2String((C4KeyShiftState) dwShiftCheck));
501  sResult.AppendChar('+');
502  }
503  // Add key
504  if (sResult.getLength())
505  {
506  sResult.Append(KeyCode2String(Key, fHumanReadable, fShort));
507  return sResult;
508  }
509  else
510  {
511  return KeyCode2String(Key, fHumanReadable, fShort);
512  }
513 }
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
uint32_t DWORD
size_t getLength() const
Definition: StdBuf.h:445
static StdStrBuf KeyShift2String(C4KeyShiftState eShift)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ deviceId

int32_t C4KeyCodeEx::deviceId

Definition at line 206 of file C4KeyboardInput.h.

Referenced by C4PlayerControl::CompileFunc().

◆ dwShift

◆ fRepeated

bool C4KeyCodeEx::fRepeated

Definition at line 210 of file C4KeyboardInput.h.

Referenced by IsRepeated().

◆ Key


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