10const char* key_strings[] = {
73 unsigned idx = key - 256;
75 return key_strings[key - 256];
81 return std::string(1, (
unsigned char) key);
85shortcut::shortcut(
unsigned short _key,
unsigned char _modifiers) : key(_key), modifiers(_modifiers)
91void shortcut::validate()
94 modifiers &= ~EM_SHIFT;
96 modifiers &= ~EM_CTRL;
102void shortcut::stream_out(std::ostream& os)
const
108bool shortcut::stream_in(std::istream& is)
110 std::string
token, read;
111 unsigned char _modifiers = 0;
112 unsigned short _key = 0;
119 bool do_not_extend_token =
false;
121 switch ((
unsigned char)c) {
143 modifiers = _modifiers;
147 if (c ==
'-' || c ==
'+') {
158 while (read.size() > 0) {
159 is.putback(read[read.size()-1]);
160 read = read.substr(0,read.size()-1);
164 do_not_extend_token =
true;
167 if (c ==
' ' || c ==
',' || c ==
';') {
171 if (!do_not_extend_token)
178 modifiers = _modifiers;
181 for (
unsigned i = 256; i < KEY_Last; ++i) {
184 modifiers = _modifiers;
189 is.putback(last_sep);
190 while (read.size() > 0) {
191 is.putback(read[read.size()-1]);
192 read = read.substr(0,read.size()-1);
198std::ostream& operator << (std::ostream& os,
const shortcut& sc)
205std::istream& operator >> (std::istream& is,
shortcut& sc)
208 is.setstate(std::ios::failbit);
the shortcut class encapsulates a key with modifiers
bool stream_in(std::istream &is)
read from stream
void stream_out(std::ostream &os) const
write to stream
std::string get_modifier_string(EventModifier modifiers)
convert a modifier combination into a readable string ending on a '+' sign if not empty,...
EventModifier
define constants for event modifiers
@ EM_META
meta modifier (windows or mac key)
@ KEY_Left_Ctrl
left ctrl key
@ KEY_Left_Alt
left alt key
@ KEY_Right_Shift
right shift key
@ KEY_Left_Shift
left shift key
@ KEY_Right_Alt
right alt key
@ KEY_Right_Ctrl
right ctrl key
std::string get_key_string(unsigned short key)
convert a key code into a readable string
namespace that holds tools that dont fit any other namespace
char to_upper(char c)
convert char to upper case
Helper functions to process strings.
representation of a token in a text by two pointers begin and end, that point to the first character ...
bool empty() const
return whether the token is empty
size_t size() const
return the length of the token in number of characters