このシステム ドライバーInpOut32 および InpOutx64を使用して、inpout32/64
ハードウェア I/O ポート コントローラーを使用しています。
これを使用して、DirectInput ゲームで発生する問題を回避しようとしています。
(SendInput
非常に長いスリープ遅延なしで入力を拒否するため、使用できません。非常に高速なキーボード入力でなければならないので、それほど長く待つことはできません)。
私は現在inpout32
、ほとんどすべてのキーボード キーに取り組んでいますが、左右の矢印キーにアクセスする方法がわかりません。
PS/2 キーボードに関するこの Web ページを見ると、PS/2 キーボードのコマンドが表示されます。
これが私が必要としているものだと分かった
0xE0, 0x4B cursor left pressed
0xE0, 0x4D cursor right pressed
これらの両方を送信するにはどうすればよいですか。それがスキャン コードであり、とがそのスキャン コードの位置であると0xE0
推測している理由がわかりませんが、私の例では動作せず、LEFT キーに対してを送信し続けます.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 が 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);
}