我正在使用使用此系统驱动程序InpOut32 和 InpOutx64inpout32/64
的硬件 I/O 端口控制器
我试图用它来绕过我在 DirectInput 游戏中遇到的问题。
(不能使用SendInput
,因为它会在没有很长的睡眠延迟的情况下拒绝输入,而且我不能等那么久,它必须是非常快的键盘输入)。
我目前inpout32
几乎所有键盘键都在工作,我不知道如何访问左/右箭头键。
通过查看有关 PS/2 键盘PS/2 键盘命令的网页
发现这是我需要的
0xE0, 0x4B cursor left pressed
0xE0, 0x4D cursor right pressed
我如何发送这两个,我不明白0xE0
我猜它是扫描码是什么,0x4B
并且0x4D
是该扫描码中的位置,但在我的示例中它不起作用它一直发送\
左键.
这是我正在使用的代码
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 返回真/假(表明它是否通过)。
新问题它会立即释放键,但不会按住键。
这是所有键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);
}