Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
异步输入函数GetKeyState和GetAsyncKeyState 以及最常见的_getch和_getwch - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章



GetKeyState ≠ GetAsyncKeyState

GetKeyState只在程序获得输入焦点时生效

GetAsyncKeyState是全局获捕


用法

if(GetKeyState(VK_CONTROL) & 0x8000)// 如果Ctrl按下
{
    //...
}
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)// 如果Ctrl按下
{
    //...
}


_getch()是char用的

_getwch()是wchar_t用的

他们有阻塞


还可以用一个宏,更方便:http://huidong.xyz/?mode=2&id=193


键值表 https://docs.microsoft.com/zh-cn/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN

ASCII码表 http://ascii.911cha.com/  



其实如果只需要用GetKeyState和GetAsyncKeyState获捕字母按键(非功能按键)的按下的话,参数直接传入大写字母即可

如:

if(GetKeyState('A') & 0x8000)// 如果A按下
{
    //...
}




返回首页


Copyright (C) 2018-2024 huidong