33using simgear::PropertyList;
73 _key_event(
fgGetNode(
"/devices/status/keyboard/event", true)),
84 if( keyboardInput == NULL )
90 if( keyboardInput ==
this )
102 SG_LOG(SG_INPUT, SG_DEBUG,
"Initializing key bindings");
103 std::string module =
"__kbd";
104 SGPropertyNode * key_nodes =
fgGetNode(
"/input/keyboard");
105 if (key_nodes == NULL) {
106 SG_LOG(SG_INPUT, SG_WARN,
"No key bindings (/input/keyboard)!!");
107 key_nodes =
fgGetNode(
"/input/keyboard",
true);
112 for (
unsigned int j = 0; j <
nasal.size(); j++) {
113 nasal[j]->setStringValue(
"module", module.c_str());
114 nasalsys->handleCommand(
nasal[j],
nullptr);
118 for (
unsigned int i = 0;
i < keys.size();
i++) {
119 int index = keys[
i]->getIndex();
120 SG_LOG(SG_INPUT, SG_DEBUG,
"Binding key " << index);
122 SG_LOG(SG_INPUT, SG_WARN,
"Key binding " << index <<
" out of range");
126 bindings[index].bindings->clear();
127 bindings[index].is_repeatable = keys[
i]->getBoolValue(
"repeatable");
128 bindings[index].last_state = 0;
135 _tiedProperties.setRoot(
fgGetNode(
"/devices/status",
true));
137 _tiedProperties.Tie<
bool>(
"keyboard/shift",
getModShift);
138 _tiedProperties.Tie<
bool>(
"keyboard/ctrl",
getModCtrl);
139 _tiedProperties.Tie<
bool>(
"keyboard/alt",
getModAlt);
140 _tiedProperties.Tie<
bool>(
"keyboard/meta",
getModMeta);
141 _tiedProperties.Tie<
bool>(
"keyboard/super",
getModSuper);
142 _tiedProperties.Tie<
bool>(
"keyboard/hyper",
getModHyper);
144 _tiedProperties.Tie(_key_event->getNode(
"key",
true), SGRawValuePointer<int>(&_key_code));
145 _tiedProperties.Tie(_key_event->getNode(
"pressed",
true), SGRawValuePointer<bool>(&_key_pressed));
146 _tiedProperties.Tie(_key_event->getNode(
"modifier",
true), SGRawValuePointer<int>(&_key_modifiers));
147 _tiedProperties.Tie(_key_event->getNode(
"modifier/shift",
true), SGRawValuePointer<bool>(&_key_shift));
148 _tiedProperties.Tie(_key_event->getNode(
"modifier/ctrl",
true), SGRawValuePointer<bool>(&_key_ctrl));
149 _tiedProperties.Tie(_key_event->getNode(
"modifier/alt",
true), SGRawValuePointer<bool>(&_key_alt));
150 _tiedProperties.Tie(_key_event->getNode(
"modifier/meta",
true), SGRawValuePointer<bool>(&_key_meta));
151 _tiedProperties.Tie(_key_event->getNode(
"modifier/super",
true), SGRawValuePointer<bool>(&_key_super));
152 _tiedProperties.Tie(_key_event->getNode(
"modifier/hyper",
true), SGRawValuePointer<bool>(&_key_hyper));
157 _tiedProperties.Untie();
167 unsigned char kc = (
unsigned char)k;
171 if (! b.
bindings[modifiers].empty())
181 return _find_key_bindings(k, modifiers&~
KEYMOD_CTRL);
187 else if ((modifiers&
KEYMOD_SHIFT) && (isupper(kc) || ispunct(kc)))
192 else if ((modifiers&
KEYMOD_ALT) && k >= 128 && k < 256)
193 return _find_key_bindings(k, modifiers&~
KEYMOD_ALT);
200void FGKeyboardInput::doKey (
int k,
int modifiers,
int x,
int y)
205 SG_LOG(SG_INPUT, SG_DEBUG,
"Key value " << k <<
" out of range");
210 _key_modifiers = modifiers >> 1;
218 _key_event->fireValueChanged();
223 modifiers = _key_modifiers << 1;
226 FGButton &b = bindings[k];
230 SG_LOG( SG_INPUT, SG_DEBUG,
"User pressed key " << k <<
" with modifiers " << modifiers );
232 const binding_list_t &bindings = _find_key_bindings(k, modifiers);
233 fireBindingList(bindings);
239 SG_LOG(SG_INPUT, SG_DEBUG,
"User released key " << k <<
" with modifiers " << modifiers);
241 const binding_list_t &bindings = _find_key_bindings(k, modifiers);
242 fireBindingList(bindings);
248void FGKeyboardInput::keyHandler(
int key,
int keymod,
int mousex,
int mousey)
251 keyboardInput->doKey(key, keymod, mousex, mousey);
257 SGSubsystemMgr::GENERAL,
258 {{
"nasal", SGSubsystemMgr::Dependency::HARD}});
void fgRegisterKeyHandler(fgKeyHandler func)
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.