如何使用GetAsyncKeyState而不调用它多次
How to use GetAsyncKeyState without calling it multiple times?
我的代码现在看起来是这样的:
if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(0x31)) {
//...
}
if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(0x32)) {
//...
}
if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(0x33)) {
//...
}
if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(0x34)) {
//...
}
if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(0x35)) {
//...
}
有没有更有效的方法来做到这一点,而不调用GetAsyncKeyState多次每个循环?也许将函数值存储为整数,然后使用switch语句?
另外,我不想使用RegisterHotKey
以下是一些建议。0. 调用函数比直接使用一个值要慢。1. if-else语句可以构建一个树。该树应通过路径压缩进行优化。你可以这样提升你的代码:
static bool keys[256];
int getkey(){ //Don't forget to call this before querying the "keys" array.
for(int i=0;i<256;i++)
GetAsyncKeyState(i);
return 0;
}
if(keys[VK_CONTROL])
{
if (keys[0x31]) {
//...
}
if (keys[0x32]) {
//...
}
if (keys[0x33]) {
//...
}
if (keys[0x34]) {
//...
}
if (keys[0x35]) {
//...
}
}
相关文章:
- 构造函数正在调用一个使用当前类类型的函数
- 在 HtmlHelp 调用中使用 HelpId
- 在调用中使用 std::vector,<double>但收到有关 std::vector<double、std::分配器>正在使用的错误<double>
- 是否可以在 make 调用中使用 BUILD_MODE
- C# 调用 C++ 如何使用 unit8 传递值
- GoogleMock:如何保存参数,以便在模拟上的下一次调用中使用
- 当被调用方法使用调用方已锁定的同一锁时,如何避免死锁
- 复制文件时如何调用取消?(使用复制文件 ex 函数和复制进度例程回调函数)
- 如何在调用其他使用 unique_lock 函数的类中使用unique_lock?
- 在函数调用中使用类型vector<pair<int,int>>::iterator&in
- 当另一个调用 lambda 使用默认捕获时,lambda 的闭包可能会被破坏吗?
- 如何在下一次函数调用中使用 STL 映射擦除从最后一个位置
- 从 C 代码链接错误调用C++函数(使用 gcc 进行链接)
- 在函数调用之前使用(void)
- 在C++的函数调用中使用模板定义的变量
- C++ - 在类构造器的调用中使用在类内声明的枚举
- 如何在新调用中使用更多参数
- 为什么在第二次调用时使用默认参数时此模板专用化失败
- 在函数调用中使用多个星号有什么用?
- c++如何调用一个使用模板的函数