diff --git a/Source/Core/InputCommon/Src/EventHandler.cpp b/Source/Core/InputCommon/Src/EventHandler.cpp index d639de22d2..465a73ca4d 100644 --- a/Source/Core/InputCommon/Src/EventHandler.cpp +++ b/Source/Core/InputCommon/Src/EventHandler.cpp @@ -7,33 +7,37 @@ EventHandler *EventHandler::m_Instance = 0; EventHandler::EventHandler() { - memset(keys, sizeof(listenFuncPtr) * (sf::Key::Escape+1)*8, 0); + for (int i=0; i= sf::Key::Escape || keys[key.keyCode][key.mods]) + // fprintf(stderr, "Registering %d:%d %p\n", key.keyCode, key.mods, func); + if (key.keyCode == sf::Key::Count || key.mods >= NUMMODS || + key.keyCode >= NUMKEYS || keys[key.keyCode][key.mods]) return false; keys[key.keyCode][key.mods] = func; } else if (key.inputType == MouseInput) { @@ -47,7 +51,8 @@ bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) { bool EventHandler::RemoveEventListener(Keys key) { if (key.inputType == KeyboardInput) { - if ((key.keyCode == sf::Key::Count || key.keyCode >= sf::Key::Escape) && ! keys[key.keyCode][key.mods]) + if ((key.keyCode == sf::Key::Count || key.keyCode >= NUMKEYS + || key.mods >= NUMMODS) && ! keys[key.keyCode][key.mods]) return false; keys[key.keyCode][key.mods] = NULL; } else if (key.inputType == MouseInput) { @@ -167,13 +172,19 @@ sf::Key::Code EventHandler::wxCharCodeToSF(int id) // case WXK_NUMLOCK: sfKey = sf::Key::Num_Lock; break; // case WXK_SCROLL: sfKey = sf::Key::Scroll_Lock; break; default: - if ((id >= 'a' && id <= 'z') || - (id >= '0' && id <= '9')) - sfKey = (sf::Key::Code)id; - else - sfKey = sf::Key::Count; // Invalid key - } + // To lower (will tolower work on windows?) + if (id >= 'A' && id <= 'Z') + id = id - 'A' + 'a'; + + if ((id >= 'a' && id <= 'z') || + (id >= '0' && id <= '9')) + sfKey = (sf::Key::Code)id; + else + sfKey = sf::Key::Count; // Invalid key + + } + return sfKey; } #endif diff --git a/Source/Core/InputCommon/Src/EventHandler.h b/Source/Core/InputCommon/Src/EventHandler.h index 7596942c2b..688f229340 100644 --- a/Source/Core/InputCommon/Src/EventHandler.h +++ b/Source/Core/InputCommon/Src/EventHandler.h @@ -4,6 +4,9 @@ #include #include "Event.hpp" +#define NUMKEYS 300 +#define NUMMODS 8 + typedef bool (*listenFuncPtr) (sf::Event); enum InputType { @@ -18,8 +21,7 @@ enum Modifiers { UseCtrl = 4 }; -struct Keys -{ +struct Keys { InputType inputType; sf::Event::EventType eventType; sf::Key::Code keyCode; @@ -30,20 +32,21 @@ struct Keys class EventHandler { private: - listenFuncPtr keys[sf::Key::Escape+1][8]; + listenFuncPtr keys[NUMKEYS][NUMMODS]; listenFuncPtr mouse[sf::Mouse::Count+1]; listenFuncPtr joys[sf::Joy::Count+1]; std::queue eventQueue; - public: static EventHandler *m_Instance; - - // protected: + +protected: EventHandler(const EventHandler&); EventHandler& operator= (const EventHandler&); - + EventHandler(); ~EventHandler(); - + +public: + bool RegisterEventListener(listenFuncPtr func, Keys key); bool RemoveEventListener(Keys key); void Update(); diff --git a/Source/Core/InputCommon/Src/InputCommon.cpp b/Source/Core/InputCommon/Src/InputCommon.cpp index beed506f8e..fc908e8975 100644 --- a/Source/Core/InputCommon/Src/InputCommon.cpp +++ b/Source/Core/InputCommon/Src/InputCommon.cpp @@ -6,7 +6,7 @@ namespace InputCommon { void Init() { // init the event handler - //EventHandler::GetInstance(); + EventHandler::GetInstance(); } void Shutdown() { diff --git a/Source/Plugins/Plugin_PadSimpleEvnt/Src/GUI/ConfigDlg.cpp b/Source/Plugins/Plugin_PadSimpleEvnt/Src/GUI/ConfigDlg.cpp index 3fe15670b8..6d7f3e0765 100644 --- a/Source/Plugins/Plugin_PadSimpleEvnt/Src/GUI/ConfigDlg.cpp +++ b/Source/Plugins/Plugin_PadSimpleEvnt/Src/GUI/ConfigDlg.cpp @@ -189,7 +189,8 @@ void ConfigDialog::OnClose(wxCloseEvent& event) { void ConfigDialog::OnKeyDown(wxKeyEvent& event) { if(clickedButton != NULL) { int page = m_Notebook->GetSelection(); - + + fprintf(stderr, "Got key code %d\n",event.GetKeyCode()); sf::Key::Code sfcode = EventHandler::wxCharCodeToSF(event.GetKeyCode()); char sfstr[100]; EventHandler::SFKeyToString(sfcode, sfstr); diff --git a/Source/Plugins/Plugin_PadSimpleEvnt/Src/PadSimple.cpp b/Source/Plugins/Plugin_PadSimpleEvnt/Src/PadSimple.cpp index 0a1d4ddf0b..f89720d24f 100644 --- a/Source/Plugins/Plugin_PadSimpleEvnt/Src/PadSimple.cpp +++ b/Source/Plugins/Plugin_PadSimpleEvnt/Src/PadSimple.cpp @@ -115,7 +115,7 @@ bool registerKey(int nPad, int id, sf::Key::Code code, int mods) { oldKey.mods = mods; // Might be not be registered yet - eventHandler->RemoveEventListener(oldKey); + // eventHandler->RemoveEventListener(oldKey); } pad[nPad].keyForControl[id] = code; @@ -373,7 +373,7 @@ void LoadConfig() IniFile file; file.Load(FULL_CONFIG_DIR EPAD_CONFIG_FILE); - for(int i = 0; i < 4; i++) { + for(int i = 0; i < 1; i++) { char SectionName[32]; sprintf(SectionName, "PAD%i", i+1); @@ -395,19 +395,17 @@ void SaveConfig() { IniFile file; file.Load(FULL_CONFIG_DIR EPAD_CONFIG_FILE); - - for(int i = 0; i < 4; i++) - { - char SectionName[32]; - sprintf(SectionName, "PAD%i", i+1); - - file.Set(SectionName, "Attached", pad[i].bAttached); - file.Set(SectionName, "DisableOnBackground", pad[i].bDisable); - - for (int x = 0; x < NUMCONTROLS; x++) - { - file.Set(SectionName, controlNames[x], pad[i].keyForControl[x]); - } + + for(int i = 0; i < 4; i++) { + char SectionName[32]; + sprintf(SectionName, "PAD%i", i+1); + + file.Set(SectionName, "Attached", pad[i].bAttached); + file.Set(SectionName, "DisableOnBackground", pad[i].bDisable); + + for (int x = 0; x < NUMCONTROLS; x++) { + file.Set(SectionName, controlNames[x], pad[i].keyForControl[x]); + } } file.Save(FULL_CONFIG_DIR EPAD_CONFIG_FILE); }