82extern const std::map<Key,std::string>
KeyNames;
103 static_cast<int>(k)+6 :
149 bool valid(
void)
const noexcept {
return(ok_); }
205 std::string
to_string(
void)
const noexcept;
262 typedef std::pair<HalfRow,RowMask>
Base;
309 void clear(
void)
noexcept { fill_byte(
krows,0,NUMHALFROWS); }
365 bool operator!=(
const Membrane & oth)
const noexcept;
366 bool operator==(
const Membrane & oth)
const noexcept
367 {
return(!(
operator!=(oth))); }
393 { lhs &= rhs;
return lhs; }
400 { lhs |= rhs;
return lhs; }
452 {
reset(); lastmembrane_ = mem0; }
468 std::chrono::steady_clock::duration repdel =
469 std::chrono::milliseconds{700},
470 std::chrono::steady_clock::duration repper =
471 std::chrono::milliseconds{100})
noexcept
472 { keyrepdel_ = repdel; keyrepper_ = repper; }
480 std::string * lastprstr =
nullptr);
502 std::chrono::steady_clock::duration & repper)
504 { repdel = keyrepdel_; repper = keyrepper_; }
507 Mode mode(
void)
const noexcept {
return(kmode_); }
510 bool capsLock(
void)
const noexcept {
return(capslock_); }
515 {
return(lasteffectivechange_); }
522 {
return(lastmembrane_); }
526 {
return(lastpressed_.keyorkeycomb ? lastpressed_.key :
Key::NO_KEY); }
533 {
return(lastpressed_.keyorkeycomb ?
KeyComb{} : lastpressed_.keycomb);}
540 bool anyKey(
void)
const noexcept
549 std::string
to_string(
void)
const noexcept;
565 std::chrono::steady_clock::time_point lasteffectivechange_;
566 std::chrono::steady_clock::duration keyrepdel_,keyrepper_;
568 bool changeMode(
void);
569 bool changeModeAfter(
void)
noexcept;
570 bool updateReps(
void)
noexcept;
571 const std::string lastAsZXString(
void)
const noexcept;
A generic enum for adding iteration capabilities to C++11 enum class.
bool anyKey(void) const noexcept
Return TRUE if a key or combination of keys were pressed in last membr.
RowMask
Constants that are useful to select a key within a half row.
@ MK1
First key (outer) in a HalfRow.
static constexpr uint8_t MASKKEYS
Constant that serves to mask out non-keys bits from a half row status.
KeyComb(void) noexcept
Default constructor: an invalid combination.
Membrane & operator^=(const Membrane &oth) noexcept
XOR + assignment.
virtual ~Membrane(void)=default
Destructor.
bool someNewKeyPressed(const Membrane &oth) const noexcept
Check if OTH keys pressed that are not pressed in this.
Membrane & operator|=(const Membrane &oth) noexcept
OR + assignment.
void keyRepetitions(std::chrono::steady_clock::duration &repdel, std::chrono::steady_clock::duration &repper) const noexcept
Fill both arguments with the current repetition parameters.
Keyboard(const Membrane &mem0=Membrane{})
Default constructor. No key pressed, no capslock, NORMAL mode.
SetOfKeys(const KeyComb &kc)
Constructor from a given combination, or empty if KC is invalid.
unsigned char krows[NUMHALFROWS]
The membrane status.
Mode mode(void) const noexcept
Return the current keyboard mode.
Key shift(void) const
Return the shift key if valid; raise an exception otherwise.
bool someKeyUnpressed(const Membrane &oth) const noexcept
Check if this has keys of OTH unpressed.
std::string to_string(void) const noexcept
Return a string representing the whole keyboard state.
virtual ~KeyComb(void)=default
Destructor.
KeyComb combinationPressed(void) const noexcept
Get the combination that is currently pressed in the membrane, if any.
KeyComb toKeyComb(void) const noexcept
Conversion to a combination of keys.
void reset(void)
Reset the keyboard to its initial state: key pressed, NO_KEY.
std::set< Key > Base
Just syntactic sugar.
void setKeyState(const KeyComb &kc, bool pressed=true)
Change the press state of the combination KC to PRESSED.
virtual ~KeyInRow(void)=default
Destructor.
std::pair< HalfRow, RowMask > Base
Just sugar.
KeyInRow(const Base &b)
Constructor from base object. Exception if invalid.
friend Membrane operator&(Membrane lhs, const Membrane &rhs) noexcept
AND.
bool capsLock(void) const noexcept
Return the current capslock state.
static uint8_t keyToASCII(Mode km, bool capslock, Key shift, Key k)
Return the ASCII code correponding to the given key pressing SHIFT + K.
friend Membrane operator^(Membrane lhs, const Membrane &rhs) noexcept
XOR + assignment.
unsigned char numKeysPressed(void) const noexcept
Get number of keys pressed.
bool valid(void) const noexcept
Return TRUE if the combination is a valid one.
void setKeyState(Key k, bool pressed=true)
Change the press state of K to PRESSED. Exception if K is invalid.
KeyComb lastKeyComb(void) const noexcept
Get the combination of keys pressed in the last membrane fed into this.
Key other(void) const
Return the other key if valid; raise an exception otherwise.
KeyInRow(Key k)
Constructor from a key id. Exception if K is invalid.
Key lastKey(void) const noexcept
Get the key pressed in the last membrane fed into this keyboard.
KeyComb(Key shift, Key other)
Constructor of a combination with the given SHIFT and OTHER keys.
std::chrono::steady_clock::time_point lastEffectiveChange(void) const noexcept
Get the time of the last change that was recognized by the keyboard.
Mode
The keyboard modes recognized by the zx operating system.
@ EXTENDED
Extended mode (E).
@ NORMAL
Normal mode (C or L).
@ GRAPHICS
Graphics mode (G).
Membrane(void) noexcept
Default constructor: the entire membrane is set to 0.
HalfRow
Half-rows that form the membrane of the zx, in the same order as ZX port.
@ CAPS_V
Keys (outer to inner): CAPSSHIFT, Z, X, C, V.
@ P_Y
Keys: P, O, I, U, Y.
@ ZERO_SIX
Keys: 0, 9, 8, 7, 6.
@ Q_T
Keys: Q, W, E, R, T.
@ SPC_B
Keys: SPACE, SYMBOLSHIFT, M, N, B.
@ A_G
Keys: A, S, D, F, G.
@ ENTER_H
Keys: ENTER, L, K, J, H.
@ ONE_FIVE
Keys: 1, 2, 3, 4, 5.
bool newMembrane(const Membrane &newmembrane, std::string *lastprstr=nullptr)
Update state of the keyboard from the given Membrane.
std::string to_string(void) const noexcept
Return a string representing the Membrane.
void setKeyRepetitions(std::chrono::steady_clock::duration repdel=std::chrono::milliseconds{700}, std::chrono::steady_clock::duration repper=std::chrono::milliseconds{100}) noexcept
Set key repetition parameters.
static constexpr unsigned char KEYSPERROW
Number of keys per half row.
bool someKeyPressed(const Membrane &oth) const noexcept
Check if this has keys additionaly pressed to the ones of OTH.
void setKeyState(const SetOfKeys &soks, bool pressed=true)
Change the press state of the entire set SOKS to PRESSED.
virtual ~Keyboard(void)=default
Destructor.
Membrane & operator&=(const Membrane &oth) noexcept
< XOR.
SetOfKeys(const Base &b)
Constructor from an initialized set of keys.
friend Membrane operator|(Membrane lhs, const Membrane &rhs) noexcept
OR.
SetOfKeys keysPressed(void) const noexcept
Return the set of keys that are pressed currently in the membrane.
std::string to_string(void) const noexcept
Return a string describing the set of keys.
void clear(void) noexcept
Clear all keys pressed.
bool is(Key shift, Key other) const
Whether this combination is composed concretely of SHIFT + OTHER.
const Membrane & lastMembrane(void) const noexcept
Return the last membrane that this Keyboard is aware of.
SetOfKeys(void)=default
Default constructor: an empty set of keys.
KeyInRow(HalfRow h=CAPS_V, RowMask m=MK1)
Default constructor, and from row and mask. Exception if invalid.
std::string to_string(void) const noexcept
Convert the combination to a string.
bool keyState(Key k) const noexcept
Return the state of key K in the membrane. FALSE if K is invalid.
Membrane operator~(void) noexcept
NOT.
static void checkPair(const Base &b)
Throw an exception if B contains an invalid half row or mask.
The ZX keyboard as it behaves (for typing) under the ZX operating system.
The zx keyboard as a membrane. Useful for games and those sort of things.
Complete definition of a key in the membrane.
A set of several keys, not repeated.
The main namespace of the library, that spans across all the zx modules.
const std::map< Key, std::string > KeyNames
This constant holds printable/descriptive names for the keys.
constexpr char keyToNumber(Key k)
Return the number of the key [0..9] if K is a number key; -1 if it is not.
const char KeySymbols[2][static_cast< int >(Key::NUMKEYS)]
This constant holds the symbols printed in the keys.
const char KeyLetters[2][static_cast< int >(Key::NUMKEYS)]
This constant holds the single letters printed in the keys.
IterableEnum< Key > ItKey
Enhanced Key type.
Key
A single key in the zx keyboard.
@ X
Key in the 1st half-row.
@ CAPS_SHIFT
Key in the 1st half-row.
@ C
Key in the 1st half-row.
@ Z
Key in the 1st half-row.
@ FIRST
Needed for enhancing the enum.
@ ENTER
Key in the 7th half-row.
@ E
Key in the 3rd half-row.
@ N6
Key in the 5th half-row.
@ P
Key in the 6th half-row.
@ U
Key in the 6th half-row.
@ V
Key in the 1st half-row.
@ Y
Key in the 6th half-row.
@ S
Key in the 2nd half-row.
@ W
Key in the 3rd half-row.
@ SPACE
Key in the 8th half-row.
@ M
Key in the 8th half-row.
@ N0
Key in the 5th half-row.
@ N8
Key in the 5th half-row.
@ A
Key in the 2nd half-row.
@ F
Key in the 2nd half-row.
@ N1
Key in the 4th half-row.
@ SYMBOL_SHIFT
Key in the 8th half-row.
@ N
Key in the 8th half-row.
@ B
Key in the 8th half-row.
@ K
Key in the 7th half-row.
@ N3
Key in the 4th half-row.
@ N4
Key in the 4th half-row.
@ T
Key in the 3rd half-row.
@ N5
Key in the 4th half-row.
@ N7
Key in the 5th half-row.
@ H
Key in the 7th half-row.
@ N2
Key in the 4th half-row.
@ L
Key in the 7th half-row.
@ I
Key in the 6th half-row.
@ G
Key in the 2nd half-row.
@ R
Key in the 3rd half-row.
@ Q
Key in the 3rd half-row.
@ O
Key in the 6th half-row.
@ LAST
Needed for enhancing the enum.
@ D
Key in the 2nd half-row.
@ N9
Key in the 5th half-row.
@ J
Key in the 7th half-row.
constexpr bool keyIsShift(Key k)
Return TRUE if K is caps or symbol.