1 #ifndef ENABLER_INPUT_H
2 #define ENABLER_INPUT_H
10 #include "keybindings.h"
16 REPEAT_NOT
, // Don't repeat at all. Furthermore, cancel other repeats.
17 REPEAT_SLOW
, // Repeat normally.
18 REPEAT_FAST
// Repeat instantly, without waiting for the first-repeat interval.
21 enum MatchType
{ type_unicode
, type_key
, type_button
};
24 std::string
translate_mod(Uint8 mod
);
25 int decode_utf8(const std::string
&s
);
26 int decode_utf8_predict_length(char byte
);
27 std::string
encode_utf8(int unicode
);
35 Uint8 mod
; // not defined for type=unicode. 1: shift, 2: ctrl, 4:alt
36 Uint8 scancode
; // not defined for type=button
43 bool operator== (const EventMatch
&other
) const {
44 if (mod
!= other
.mod
) return false;
45 if (type
!= other
.type
) return false;
47 case type_unicode
: return unicode
== other
.unicode
;
48 case type_key
: return key
== other
.key
;
49 case type_button
: return button
== other
.button
;
50 default: return false;
54 bool operator< (const EventMatch
&other
) const {
55 if (mod
!= other
.mod
) return mod
< other
.mod
;
56 if (type
!= other
.type
) return type
< other
.type
;
58 case type_unicode
: return unicode
< other
.unicode
;
59 case type_key
: return key
< other
.key
;
60 case type_button
: return button
< other
.button
;
61 default: return false;
71 typedef std::list
<std::set
<InterfaceKey
> > macro
;
73 struct RegisteredKey
{
78 class enabler_inputst
{
79 std::set
<InterfaceKey
> key_translation(EventMatch
&match
);
81 Repeat
key_repeat(InterfaceKey
);
82 void key_repeat(InterfaceKey
, Repeat
);
83 void load_macro_from_file(const std::string
&file
);
84 void save_macro_to_file(const std::string
&file
, const std::string
&name
, const macro
&);
86 // In practice.. do not use this one.
87 void add_input(SDL_Event
&e
, Time now
);
88 // Use this one. It's much nicer.
89 void add_input_refined(KeyEvent
&e
, Time now
, int serial
);
90 // Made specifically for curses. <0 = unicode, >0 = ncurses symbols.
92 void add_input_ncurses(int key
, Time now
, bool esc
);
94 std::set
<InterfaceKey
> get_input(Time now
);
97 void load_keybindings(const std::string
&file
);
98 void save_keybindings(const std::string
&file
);
99 void save_keybindings();
100 std::string
GetKeyDisplay(int binding
);
101 std::string
GetBindingDisplay(int binding
);
102 std::string
GetBindingTextDisplay(int binding
);
105 void record_input(); // Records input until such a time as you say stop
106 void record_stop(); // Stops recording, saving it as the active macro
108 void play_macro(); // Runs the active macro, if any
109 bool is_macro_playing();
110 std::list
<string
> list_macros();
111 void load_macro(string name
); // Loads some macro as the active one
112 void save_macro(string name
); // Saves the active macro under some name
113 void delete_macro(string name
);
116 bool prefix_building();
117 void prefix_toggle();
118 void prefix_add_digit(char digit
);
122 // Updating the key-bindings
123 void register_key(); // Sets the next key-press to be stored instead of executed.
124 list
<RegisteredKey
> getRegisteredKey(); // Returns a description of stored keys. Max one of each type.
125 void bindRegisteredKey(MatchType type
, InterfaceKey key
); // Binds one of the stored keys to key
126 bool is_registering(); // Returns true if we're still waiting for a key-hit
128 std::list
<EventMatch
> list_keys(InterfaceKey key
); // Returns a list of events matching this interfacekey
129 void remove_key(InterfaceKey key
, EventMatch ev
); // Removes a particular matcher from the keymap.