UP 模拟器 加入key的模拟支持

This commit is contained in:
JiXieShi
2024-06-22 22:51:58 +08:00
parent 0c7c6bb1e9
commit 5876461531
9 changed files with 201 additions and 35 deletions

83
sim/key/key.cpp Normal file
View File

@@ -0,0 +1,83 @@
#include "sim_key.h"
#include "log.h"
#include<easyx.h>
#include<conio.h>
uint8_t SIM_Key_Scan() {
uint8_t key = 0;
if (_kbhit()) {
char keys = _getch();
switch (keys) {
//上键
case 72:
case 'w':
case 'W':
key = SIM_KEY_UP;
break;
case 80:
case 's':
case 'S':
key = SIM_KEY_DOWN;
break;
//左键
case 75:
case 'a':
case 'A':
key = SIM_KEY_LEFT;
break;
//右键
case 77:
case 'd':
case 'D':
key = SIM_KEY_RIGHT;
break;
case 'q':
case 'Q':
key = SIM_KEY_SET;
break;
case 'e':
case 'E':
key = SIM_KEY_ENABLE;
break;
case 'r':
case 'R':
key = SIM_KEY_RESET;
break;
}
}
return key;
}
uint8_t SIM_Key_UP(uint8_t) {
return GetAsyncKeyState(VK_UP);
}
uint8_t SIM_Key_DOWN(uint8_t l) {
// uint8_t k=GetAsyncKeyState(VK_DOWN);
// LOGT("SIM","KEYID:%d-DOWN:%d",l,k);
return GetAsyncKeyState(VK_DOWN);
}
uint8_t SIM_Key_LEFT(uint8_t) {
return GetAsyncKeyState(VK_LEFT);
}
uint8_t SIM_Key_RIGHT(uint8_t) {
return GetAsyncKeyState(VK_RIGHT);
}
uint8_t SIM_Key_ENABLE(uint8_t) {
return GetAsyncKeyState(VK_RETURN);
}
uint8_t SIM_Key_SET(uint8_t) {
return GetAsyncKeyState(VK_RSHIFT);
}
uint8_t SIM_SIM_Key_RESET(uint8_t) {
return GetAsyncKeyState(VK_END);
}

36
sim/key/sim_key.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef HW_LIB_SIM_KEY_H
#define HW_LIB_SIM_KEY_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stdint.h"
typedef enum Key_map {
SIM_KEY_UP = 1,
SIM_KEY_DOWN,
SIM_KEY_LEFT,
SIM_KEY_RIGHT,
SIM_KEY_ENABLE,
SIM_KEY_SET,
SIM_KEY_RESET
} Key_Map_t;
uint8_t SIM_Key_Scan();
uint8_t SIM_Key_UP(uint8_t l);
uint8_t SIM_Key_DOWN(uint8_t l);
uint8_t SIM_Key_LEFT(uint8_t l);
uint8_t SIM_Key_RIGHT(uint8_t l);
uint8_t SIM_Key_ENABLE(uint8_t l);
uint8_t SIM_Key_SET(uint8_t l);
uint8_t SIM_Key_RESET(uint8_t l);
#ifdef __cplusplus
}
#endif
#endif //HW_LIB_SIM_KEY_H