为什么在VS中左键单击控制台时控制台程序中断?
Why is the console program interrupted when I Left-click on the console in VS?
我在VS中写了一个控制台程序来响应鼠标事件。我想在点击时打印一些东西,所以我写了这段代码:
int keyPressed(int key){
return (GetAsyncKeyState(key) & 0x8000 != 0);
}
void Mouse::click(){
while (1)
{
if (keyPressed(VK_LBUTTON) || keyPressed(VK_RBUTTON)){
cout << "click\n";
}
}
}
int main(){
Mouse mouse;
while (1){
mouse.click();
}
}
当我左键单击时,"click" 不打印,但如果我按下键盘或右键单击,它被打印。
这是怎么回事?我该如何处理?谢谢~
!=
has a higher precedence than &
,因此 0x8000 != 0
在 &
生效之前计算。
使用括号 -- 将该行更改为:
return (GetAsyncKeyState(key) & 0x8000) != 0;
我在VS中写了一个控制台程序来响应鼠标事件。我想在点击时打印一些东西,所以我写了这段代码:
int keyPressed(int key){
return (GetAsyncKeyState(key) & 0x8000 != 0);
}
void Mouse::click(){
while (1)
{
if (keyPressed(VK_LBUTTON) || keyPressed(VK_RBUTTON)){
cout << "click\n";
}
}
}
int main(){
Mouse mouse;
while (1){
mouse.click();
}
}
当我左键单击时,"click" 不打印,但如果我按下键盘或右键单击,它被打印。
这是怎么回事?我该如何处理?谢谢~
!=
has a higher precedence than &
,因此 0x8000 != 0
在 &
生效之前计算。
使用括号 -- 将该行更改为:
return (GetAsyncKeyState(key) & 0x8000) != 0;