Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cInputKey.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cInputKey_H
7 #define _INC_cInputKey_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cInputBase.h"
14 
15 namespace GrayLib
16 {
18  {
24 #define INPKEYDEF(a,b,c,d) INPUTKEY_##a,
25 #include "cInputKeyBase.tbl"
26 #include "cInputKeyWin.tbl"
27 #include "cInputKeyDX1.tbl"
28 #undef INPKEYDEF
30  };
31 
33  {
38  public:
41  static const cInputKeyDef k_aInputKeyDefs[INPUTKEY_QTY];
42 
43  public:
44  static INPUTKEY_TYPE GRAYCALL GetDevKeyByName(const GChar_t* pszName);
45  static INPUTKEY_TYPE GRAYCALL GetDevKeyByVKCode(VK_TYPE vKeyCode);
46 
47  const GChar_t* get_Name() const noexcept
48  {
49  return m_pszKeyName;
50  }
51  };
52 
54  {
58 
62 
63  INPKEYMASK_ALTL = 0x0004,
64  INPKEYMASK_ALTR = 0x0008,
65  INPKEYMASK_ALT = INPKEYMASK_ALTL | INPKEYMASK_ALTR, // either ALT. MOD_ALT
66 
67  INPKEYMASK_CTRLL = 0x0010,
68  INPKEYMASK_CTRLR = 0x0020,
69  INPKEYMASK_CTRL = INPKEYMASK_CTRLL | INPKEYMASK_CTRLR, // any control key MOD_CONTROL
70 
71  INPKEYMASK_BITS = 6, // how many bits does this need?
72  };
73 
74  typedef DWORD INPKEYMASK_TYPE;
75  typedef DWORD INPKEYCOMBO_t;
76 
78  {
83 
84  private:
86  INPUTKEY_TYPE m_tDevKey;
87  INPKEYMASK_TYPE m_dwKeyMask;
88 
89  public:
90  cInputKeyPress(const cInputKeyPress* pKeyBase) noexcept
91  : m_tDevKey(pKeyBase->get_DevKey())
92  , m_dwKeyMask(pKeyBase->get_KeyMask())
93  {
94  // Copy
95  ASSERT(pKeyBase != nullptr);
96  }
97  cInputKeyPress(INPUTKEY_TYPE tDevKey = INPUTKEY_NULL, INPKEYMASK_TYPE dwKeyMask = 0) noexcept
98  : m_tDevKey(tDevKey), m_dwKeyMask(dwKeyMask)
99  {
100  }
101 
102  void InitKey() noexcept
103  {
104  m_tDevKey = INPUTKEY_NULL;
105  m_dwKeyMask = 0;
106  }
107  bool isKeySet() const noexcept
108  {
109  return m_tDevKey != INPUTKEY_NULL ;
110  }
111 
112  INPUTKEY_TYPE get_DevKey() const noexcept
113  {
114  return m_tDevKey;
115  }
116  void put_DevKey(INPUTKEY_TYPE tDevKey) noexcept
117  {
118  m_tDevKey = tDevKey;
119  }
120 
121  INPKEYMASK_TYPE get_KeyMask() const noexcept
122  {
123  return m_dwKeyMask;
124  }
125  void put_KeyMask(INPKEYMASK_TYPE dwKeyMask) noexcept
126  {
127  m_dwKeyMask = dwKeyMask;
128  }
129 
130  static inline INPKEYCOMBO_t MakeSortKey(INPUTKEY_TYPE iDevKey, INPKEYMASK_TYPE dwKeyMask) noexcept
131  {
132  return (iDevKey << INPKEYMASK_BITS) | dwKeyMask;
133  }
134  INPKEYCOMBO_t get_SortValue() const noexcept
135  {
137  return MakeSortKey(m_tDevKey, m_dwKeyMask) ;
138  }
139 
140  const GChar_t* get_DevKeyName() const;
141  cString get_KeyBaseName() const;
142  };
143 };
144 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define ASSERT(exp)
Definition: cDebugAssert.h:87
int VK_TYPE
a type of physical key in _WIN32. "#define VK_UP" etc. NOT the same as a scan code.
Definition: cInputBase.h:27
Definition: cInputKey.h:33
const GChar_t * m_pszKeyName
'cInputKeyDefs.tbl' name of a key on the device (keyboard).
Definition: cInputKey.h:39
const GChar_t * get_Name() const noexcept
Definition: cInputKey.h:47
VK_TYPE m_vKeyCode
Windows VK codes. e.g. VK_ESCAPE.
Definition: cInputKey.h:40
Definition: cInputKey.h:78
cInputKeyPress(const cInputKeyPress *pKeyBase) noexcept
Definition: cInputKey.h:90
INPKEYCOMBO_t get_SortValue() const noexcept
Definition: cInputKey.h:134
cInputKeyPress(INPUTKEY_TYPE tDevKey=INPUTKEY_NULL, INPKEYMASK_TYPE dwKeyMask=0) noexcept
Definition: cInputKey.h:97
INPUTKEY_TYPE get_DevKey() const noexcept
Definition: cInputKey.h:112
INPKEYMASK_TYPE get_KeyMask() const noexcept
Definition: cInputKey.h:121
void InitKey() noexcept
Definition: cInputKey.h:102
bool isKeySet() const noexcept
Definition: cInputKey.h:107
void put_KeyMask(INPKEYMASK_TYPE dwKeyMask) noexcept
Definition: cInputKey.h:125
void put_DevKey(INPUTKEY_TYPE tDevKey) noexcept
Definition: cInputKey.h:116
static INPKEYCOMBO_t MakeSortKey(INPUTKEY_TYPE iDevKey, INPKEYMASK_TYPE dwKeyMask) noexcept
Definition: cInputKey.h:130
Definition: cMesh.h:22
DWORD INPKEYCOMBO_t
HASHCODE_t from MakeSortKey() = alt + key as a single value for sorting.
Definition: cInputKey.h:75
DWORD INPKEYMASK_TYPE
SHIFT, ALT, CTRL.
Definition: cInputKey.h:74
INPKEYMASK_TYPE_
Definition: cInputKey.h:54
@ INPKEYMASK_CTRLR
Definition: cInputKey.h:68
@ INPKEYMASK_SHIFTL
Definition: cInputKey.h:59
@ INPKEYMASK_SHIFTR
Definition: cInputKey.h:60
@ INPKEYMASK_SHIFT
Definition: cInputKey.h:61
@ INPKEYMASK_ALTL
Definition: cInputKey.h:63
@ INPKEYMASK_CTRL
Definition: cInputKey.h:69
@ INPKEYMASK_BITS
Definition: cInputKey.h:71
@ INPKEYMASK_CTRLL
Definition: cInputKey.h:67
@ INPKEYMASK_ALT
Definition: cInputKey.h:65
@ INPKEYMASK_ALTR
Definition: cInputKey.h:64
INPUTKEY_TYPE
Definition: cInputKey.h:18
@ INPUTKEY_QTY
Definition: cInputKey.h:29
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26