我正在使用inpout32/64
硬件I / O端口控制器使用此系统驱动程序InpOut32 and InpOutx64
我正在尝试使用它来绕过我在DirectInput游戏中遇到的问题
(不能使用SendInput
,因为它会在没有很长睡眠延迟的情况下拒绝输入,而且我不能等待那么长时间它必须是非常快速的键盘输入。)
我目前只有inpout32
为我的所有键盘按键工作,我无法弄清楚如何访问左/右箭头键。
查看此网页有关PS / 2键盘PS/2 Keyboard commands
的信息想出这就是我需要的东西
0xE0, 0x4B cursor left pressed
0xE0, 0x4D cursor right pressed
我如何发送这两个,我不明白是什么0xE0
我猜测它是扫描代码而0x4B
和0x4D
是其中的位置扫描代码,但它在我的示例中不起作用,它继续为LEFT键发送\
。
这是我正在使用的代码
BOOL isDriverOn = false;
#define LEFT 0x4B
#define RIGHT 0x4D
void setup() {
isDriverOn = IsInpOutDriverOpen();
}
//void _stdcall Out32(short PortAddress, short data);
//short _stdcall Inp32(short PortAddress);
void DD_PS2command(short comm, short value) {
if(!isDriverOn) {
printf("PS/2 Keyboard port driver is not opened\n");
return;
}
//keyboard wait.
int kb_wait_cycle_counter = 1000;
while((Inp32(0x64) & 0x02) && kb_wait_cycle_counter--) //wait to get communication.
Sleep(1);
if(kb_wait_cycle_counter) { //if it didn't timeout.
Out32(0x64, comm); //send command
kb_wait_cycle_counter = 1000;
while((Inp32(0x64) & 0x02) && kb_wait_cycle_counter--) //wait to get communication.
Sleep(1);
if(!kb_wait_cycle_counter) {
printf("failed to get communication in cycle counter timeout), who knows what will happen now\n");
//return false;
}
Out32(0x60, value); //send data as short
Sleep(1);
//return true;
} else {
printf("failed to get communication in counter timeout, busy)\n");
//return false;
}
}
void DD_Button(short btn, bool release = false, int delay = 0)
{
//0xE0, 0x4B {Left}
//0xE0, 0x4D {Rght}
//return scode | (release?0x80:0x00);
short scan_code = 0;
if(btn == LEFT)
scan_code = LEFT + 0xE0;
else if(btn == RIGHT)
scan_code = RIGHT + 0xE0;
else
scan_code = 0x0;
scan_code |= (release ? 0x80 : 0x00);
if(delay)
Sleep(delay);
DD_PS2command(0xD2, scan_code);
}
编辑:问题解决了,下面这个函数有效,只需要让DD_PS2command返回true / false(表示它是否通过)。
新问题它会立即释放密钥而不会按住密钥。
以下是所有键http://www.computer-engineering.org/ps2keyboard/scancodes1.html
void DD_Button(short btn, bool release = false, int delay = 0)
{
//;0xE0, 0x4B {Left}
//;0xE0, 0x4D {Rght}
// return scode | (release? 0x80: 0x00)
short scan_code = 0;
bool good = false;
switch(btn) {
case LEFT:
case RIGHT:
scan_code = btn;
//send extended byte first (grey code)
good = DD_PS2command(0xD2, 0xE0);
break;
}
printf("good = %d\n", good);
scan_code |= (release ? 0x80 : 0x00);
if(delay)
Sleep(delay);
//0xD2 - Write keyboard output buffer
good = DD_PS2command(0xD2, scan_code);
printf("2 good = %d\n", good);
}
答案 0 :(得分:1)
0xE0
是扩展密钥的转义码 - 例如,对于左侧,您发送0xE0
,然后立即发送0x4B
。