如何同时读取键盘上的按键? [英] How to simultaneous read keys on keyboard?

查看:122
本文介绍了如何同时读取键盘上的按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与我的孩子年龄有关,当我玩了一款新游戏时,印象深刻.

My question behave to my children age, when I got a new game to play, and was very impressed.

该游戏能够看到并响应超过4,6(有时8个键)的反应.这怎么可能?有限制吗?或者,如果我全部按"a,s,d,f,u,v,shift,0,uparrow,rightcltr,return和Backspace键",程序可以读取它"吗?对此的一些介绍(用C,bashscript,javascript或phyton)将受到高度赞赏.感谢您在这里所做的一切.

The game was able to see and react to more than 4,6 sometimes 8 keys pressed at same time. How is this possible? There is a limit for this? Or if I press "a,s,d,f,u,v,shift,0,uparrow,rightcltr,return and backspace" all thogheter, a program can "read it"? Some introduction about it (in C, bashscript, javascript, or phyton) will be highly appreciated. Thanks for any effort here.

推荐答案

如果我们在谈论Windows,请

If we are speaking about Windows, GetKeyboardState() copies the status of the 256 virtual keys to the specified buffer.

BYTE keys[256];

if(GetKeyboardState(keys))
{

   //check if A key is pressed
   if((keys[VK_A]&0xF0) && !(prevKeys[VK_A]&0xF0)) 
   {
     DoAPressed();
   }
   //check if S key is pressed too
   if((keys[VK_S]&0xF0) && !(prevKeys[VK_S]&0xF0)) 
   {
     DoSPressed();
   }
   // the same goes for all keys you want to check
}

这篇关于如何同时读取键盘上的按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆