Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <Windows.h>
  2. #include "calamarilua.h"
  3.  
  4. int KeyStateCount = 0;
  5. KeyState KeyStates[0x100];
  6. void RegisterKey(int pKey, bool* condition) {
  7. KeyState keyState = *new KeyState();
  8. keyState.vKey = pKey;
  9. keyState.Modifier = -1;
  10. keyState.condition = condition;
  11. KeyStates[KeyStateCount] = keyState;
  12. KeyStateCount++;
  13. }
  14.  
  15. void RegisterKeyWithModifier(int pKey, int Modifier, bool* condition) {
  16. KeyState keyState = *new KeyState();
  17. keyState.vKey = pKey;
  18. keyState.Modifier = Modifier;
  19. keyState.condition = condition;
  20. KeyStates[KeyStateCount] = keyState;
  21. KeyStateCount++;
  22. }
  23.  
  24. void KeyLoop() {
  25. for (int i = 0; i < 64; i++) {
  26. if (luaKeyHandlerList[i] == 0)
  27. continue;
  28. KeyState key = luaKeyHandlerList[i]->keyState;
  29. if (GetAsyncKeyState(key.vKey) < 0 && !key.State) {
  30. if (key.Modifier == -1 || GetAsyncKeyState(key.Modifier)) {
  31. lua_rawgeti(lState, LUA_REGISTRYINDEX, luaKeyHandlerList[i]->luaFuncRef);
  32. lua_pushvalue(lState, 1);
  33. int ret = lua_pcall(lState, 0, 0, 0);
  34. if (ret != LUA_OK)
  35. printf("Error: %s\n", lua_tostring(lState, -1));
  36. lua_pop(lState, lua_gettop(lState));
  37. }
  38. }
  39. if (GetAsyncKeyState(key.vKey) == 0 && key.State) {
  40. if (key.Modifier == -1 || GetAsyncKeyState(key.Modifier)) {
  41. key.State = false;
  42. }
  43. }
  44. }
  45. for (int i = 0; i < KeyStateCount; i++) {
  46. {
  47. if (GetAsyncKeyState(KeyStates[i].vKey) < 0 && !KeyStates[i].State) {
  48. if (KeyStates[i].Modifier == -1 || GetAsyncKeyState(KeyStates[i].Modifier)) {
  49. KeyStates[i].State = true;
  50. }
  51. }
  52. if (GetAsyncKeyState(KeyStates[i].vKey) == 0 && KeyStates[i].State) {
  53. if (KeyStates[i].Modifier == -1 || GetAsyncKeyState(KeyStates[i].Modifier) ) {
  54. KeyStates[i].State = false;
  55. *KeyStates[i].condition = !*KeyStates[i].condition;
  56. }
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement