multiple simultaneous key press c#

浪尽此生 提交于 2019-12-19 20:41:11

问题


I am programming a game in microsoft visual studio c# and I have to catch lot's of keys simultaneously. I can't detect Q,W,E,R,T,Y at the same time but I can detect Q,W,E,R,T,A.

I tried to use KeyDown and [DllImport("user32.dll")] but both of them has the same result. What is the difference between Y and A keys and how can I solve this problem?

int code1 = GetVirtualKeyCode(Keys.Q);
int code2 = GetVirtualKeyCode(Keys.W);
int code3 = GetVirtualKeyCode(Keys.E);
int code4 = GetVirtualKeyCode(Keys.R);
int code5 = GetVirtualKeyCode(Keys.T);
int code6 = GetVirtualKeyCode(Keys.Y);
if ((array[code1] & 0x80) != 0 &&
    (array[code2] & 0x80) != 0 &&
    (array[code3] & 0x80) != 0 &&
    (array[code4] & 0x80) != 0 &&
    (array[code5] & 0x80) != 0 &&
    (array[code6] & 0x80) != 0)
{
    listBox1.Items.Add("asdasdasd");
}

回答1:


It may be related to your keyboard. When I was a gamer, I know that it was a property of keyboards to be able to send multiple keystrokes at the same time; Depending on the keyboard, the number would differ, but also the different combinations would or wouldn't work.




回答2:


This is known as key rollover. USB keyboards only support a finite key rollover, whereas some cleverly-designed PS/2 keyboards have n-key rollover (many many keys may be depressed at the same time without muting additional keypresses)

Have a read: Wikipedia Description



来源:https://stackoverflow.com/questions/16673728/multiple-simultaneous-key-press-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!