Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include "calamarilua.h"
- int KeyStateCount = 0;
- KeyState KeyStates[0x100];
- void RegisterKey(int pKey, bool* condition) {
- KeyState keyState = *new KeyState();
- keyState.vKey = pKey;
- keyState.Modifier = -1;
- keyState.condition = condition;
- KeyStates[KeyStateCount] = keyState;
- KeyStateCount++;
- }
- void RegisterKeyWithModifier(int pKey, int Modifier, bool* condition) {
- KeyState keyState = *new KeyState();
- keyState.vKey = pKey;
- keyState.Modifier = Modifier;
- keyState.condition = condition;
- KeyStates[KeyStateCount] = keyState;
- KeyStateCount++;
- }
- void KeyLoop() {
- for (int i = 0; i < 64; i++) {
- if (luaKeyHandlerList[i] == 0)
- continue;
- KeyState key = luaKeyHandlerList[i]->keyState;
- if (GetAsyncKeyState(key.vKey) < 0 && !key.State) {
- if (key.Modifier == -1 || GetAsyncKeyState(key.Modifier)) {
- lua_rawgeti(lState, LUA_REGISTRYINDEX, luaKeyHandlerList[i]->luaFuncRef);
- lua_pushvalue(lState, 1);
- int ret = lua_pcall(lState, 0, 0, 0);
- if (ret != LUA_OK)
- printf("Error: %s\n", lua_tostring(lState, -1));
- lua_pop(lState, lua_gettop(lState));
- }
- }
- if (GetAsyncKeyState(key.vKey) == 0 && key.State) {
- if (key.Modifier == -1 || GetAsyncKeyState(key.Modifier)) {
- key.State = false;
- }
- }
- }
- for (int i = 0; i < KeyStateCount; i++) {
- {
- if (GetAsyncKeyState(KeyStates[i].vKey) < 0 && !KeyStates[i].State) {
- if (KeyStates[i].Modifier == -1 || GetAsyncKeyState(KeyStates[i].Modifier)) {
- KeyStates[i].State = true;
- }
- }
- if (GetAsyncKeyState(KeyStates[i].vKey) == 0 && KeyStates[i].State) {
- if (KeyStates[i].Modifier == -1 || GetAsyncKeyState(KeyStates[i].Modifier) ) {
- KeyStates[i].State = false;
- *KeyStates[i].condition = !*KeyStates[i].condition;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement