UP 模拟器 加入key的模拟支持
This commit is contained in:
83
sim/key/key.cpp
Normal file
83
sim/key/key.cpp
Normal 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
36
sim/key/sim_key.h
Normal 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
|
@@ -37,6 +37,7 @@ void drawOledPixel(int oledX, int oledY) {
|
||||
|
||||
|
||||
void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) {
|
||||
BeginBatchDraw();
|
||||
cleardevice();
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
@@ -47,6 +48,7 @@ void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) {
|
||||
}
|
||||
}
|
||||
}
|
||||
EndBatchDraw();
|
||||
}
|
||||
|
||||
|
||||
|
14
sim/thread/sim_thread.h
Normal file
14
sim/thread/sim_thread.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef HW_LIB_SIM_THREAD_H
|
||||
#define HW_LIB_SIM_THREAD_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*Thread_Func_t)(void *pArg);
|
||||
|
||||
void ThreadCreat(Thread_Func_t func, unsigned int stackSize, void *pArg);
|
||||
void ThreadStop();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif //HW_LIB_SIM_THREAD_H
|
11
sim/thread/thread.cpp
Normal file
11
sim/thread/thread.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "sim_thread.h"
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
|
||||
void ThreadCreat(Thread_Func_t func, unsigned int stackSize, void *pArg) {
|
||||
_beginthread(func, stackSize, pArg);
|
||||
}
|
||||
|
||||
void ThreadStop() {
|
||||
_endthread();
|
||||
}
|
Reference in New Issue
Block a user