diff --git a/WickedEngine/wiInputManager.cpp b/WickedEngine/wiInputManager.cpp index 6c15b4ed2..217f8c6cc 100644 --- a/WickedEngine/wiInputManager.cpp +++ b/WickedEngine/wiInputManager.cpp @@ -11,9 +11,11 @@ wiInputManager::InputCollection wiInputManager::inputs; #ifndef WINSTORE_SUPPORT #define KEY_DOWN(vk_code) (GetAsyncKeyState(vk_code) < 0) #define KEY_TOGGLE(vk_code) ((GetAsyncKeyState(vk_code) & 1) != 0) +#define MOUSEBUTTONDOWN(vk_code) (GetAsyncKeyState(vk_code) & 0x8000) #else #define KEY_DOWN(vk_code) (false) #define KEY_TOGGLE(vk_code) (false) +#define MOUSEBUTTONDOWN(vk_code) (false) #endif //WINSTORE_SUPPORT #define KEY_UP(vk_code) (!KEY_DOWN(vk_code)) @@ -88,6 +90,9 @@ bool wiInputManager::down(DWORD button, InputType inputType, short playerindex) return true; } break; + case MOUSE: + return MOUSEBUTTONDOWN(static_cast(button)) != 0; + break; default:break; } return false; diff --git a/WickedEngine/wiInputManager.h b/WickedEngine/wiInputManager.h index 0627238b6..e684ef9e5 100644 --- a/WickedEngine/wiInputManager.h +++ b/WickedEngine/wiInputManager.h @@ -19,11 +19,13 @@ public: static void Update(); static void CleanUp(); + // do not change order! (it is used in lua) enum InputType{ DIRECTINPUT_JOYPAD, XINPUT_JOYPAD, KEYBOARD, RAWINPUT_JOYPAD, + MOUSE, INPUTTYPE_COUNT }; struct Input{ diff --git a/WickedEngine/wiInputManager_BindLua.cpp b/WickedEngine/wiInputManager_BindLua.cpp index 89996dae5..acfd74317 100644 --- a/WickedEngine/wiInputManager_BindLua.cpp +++ b/WickedEngine/wiInputManager_BindLua.cpp @@ -23,7 +23,12 @@ int wiInputManager_BindLua::Down(lua_State* L) if (argc > 0) { int code = wiLua::SGetInt(L, 1); - wiLua::SSetBool( L, wiInputManager::down((DWORD)code) ); + wiInputManager::InputType type = wiInputManager::KEYBOARD; + if (argc > 1) + { + type = (wiInputManager::InputType)wiLua::SGetInt(L, 2); + } + wiLua::SSetBool(L, wiInputManager::down((DWORD)code, type)); return 1; } return 0; @@ -34,7 +39,12 @@ int wiInputManager_BindLua::Press(lua_State* L) if (argc > 0) { int code = wiLua::SGetInt(L, 1); - wiLua::SSetBool(L, wiInputManager::press((DWORD)code)); + wiInputManager::InputType type = wiInputManager::KEYBOARD; + if (argc > 1) + { + type = (wiInputManager::InputType)wiLua::SGetInt(L, 2); + } + wiLua::SSetBool(L, wiInputManager::press((DWORD)code, type)); return 1; } return 0; @@ -50,7 +60,17 @@ int wiInputManager_BindLua::Hold(lua_State* L) { duration = wiLua::SGetInt(L, 2); } - wiLua::SSetBool(L, wiInputManager::hold((DWORD)code, (DWORD)duration)); + bool continuous = false; + if (argc > 2) + { + continuous = wiLua::SGetBool(L, 3); + } + wiInputManager::InputType type = wiInputManager::KEYBOARD; + if (argc > 3) + { + type = (wiInputManager::InputType)wiLua::SGetInt(L, 4); + } + wiLua::SSetBool(L, wiInputManager::hold((DWORD)code, (DWORD)duration, continuous, type)); return 1; } return 0; @@ -89,6 +109,13 @@ void wiInputManager_BindLua::Bind() Luna::Register(wiLua::GetGlobal()->GetLuaState()); wiLua::GetGlobal()->RunText("input = InputManager()"); + //Input types + wiLua::GetGlobal()->RunText("DIRECTINPUT_JOYPAD = 0"); + wiLua::GetGlobal()->RunText("XINPUT_JOYPAD = 1"); + wiLua::GetGlobal()->RunText("KEYBOARD = 2"); + wiLua::GetGlobal()->RunText("RAWINPUT_JOYPAD = 3"); + wiLua::GetGlobal()->RunText("MOUSE = 4"); + //Keyboard wiLua::GetGlobal()->RunText("VK_UP = 0x26"); wiLua::GetGlobal()->RunText("VK_DOWN = 0x28");