(true&&false&&false)=true? 关于GetAsyncKeyState

6lilu9 2018-06-17 10:00:20

if ((SystemService.GetAsyncKeyState(17) != 0) && (SystemService.GetAsyncKeyState(76) != 0) && (SystemService.GetAsyncKeyState(73) != 0))//同时ctrl,l,i
{
MessageBox.Show("SystemService.GetAsyncKeyState(17)的状态值:" + SystemService.GetAsyncKeyState(17) + "\nSystemService.GetAsyncKeyState(76)键的状态值:" + SystemService.GetAsyncKeyState(76) + "\nSystemService.GetAsyncKeyState(73)键的状态值:" + SystemService.GetAsyncKeyState(73));
}


上述是我为某个程序设的热键,按ctrl+l+i启动。

当同时按下ctrl,L, I的键时确实能启动,但后期才发现除了同时按下按下ctrl,L, I能启动外,下面两种操作也能启动热键,分别是:①依次按下L,I,ctrl,能启动 ②依次按下I,L,CTRL也能启动,
值得说明的是,依次按下ctrl,L,I 不能启动。

我于时找原因测试,结果就发现了附图,当①依次按下L,I,ctrl,时,条件语句
 if ((SystemService.GetAsyncKeyState(17) != 0) && (SystemService.GetAsyncKeyState(76) != 0) && (SystemService.GetAsyncKeyState(73) != 0))

就简化为了:
if(true&&false&&false)

,这个小学生都知道应该是false,不执行if里语句呀,但事实确实是执行了。
执行了,还告诉我不应该执行。


...全文
1279 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
巴士上的邂逅 2018-06-19
  • 打赏
  • 举报
回复
引用 1 楼 yuankaiwsl 的回复:
把SystemService.GetAsyncKeyState(17) != 0之类定义一下变量看看真的是不是你所想象的
要多试,不要想当然
6lilu9 2018-06-19
  • 打赏
  • 举报
回复
引用 3 楼 yuankaiwsl 的回复:
试一下和这段代码显示的一样吗
            var a = (SystemService.GetAsyncKeyState(17) != 0);
            var b = (SystemService.GetAsyncKeyState(76) != 0);
            var c = (SystemService.GetAsyncKeyState(73) != 0);
            if (a && b && c)//同时ctrl,l,i
            {
                MessageBox.Show("SystemService.GetAsyncKeyState(17)的状态值:" + a + "\nSystemService.GetAsyncKeyState(76)键的状态值:" + b + "\nSystemService.GetAsyncKeyState(73)键的状态值:" + c);
            }
巴士上的邂逅 2018-06-17
  • 打赏
  • 举报
回复
把SystemService.GetAsyncKeyState(17) != 0之类定义一下变量看看真的是不是你所想象的
巴士上的邂逅 2018-06-17
  • 打赏
  • 举报
回复
试一下和这段代码显示的一样吗
            var a = (SystemService.GetAsyncKeyState(17) != 0);
            var b = (SystemService.GetAsyncKeyState(76) != 0);
            var c = (SystemService.GetAsyncKeyState(73) != 0);
            if (a && b && c)//同时ctrl,l,i
            {
                MessageBox.Show("SystemService.GetAsyncKeyState(17)的状态值:" + a + "\nSystemService.GetAsyncKeyState(76)键的状态值:" + b + "\nSystemService.GetAsyncKeyState(73)键的状态值:" + c);
            }
6lilu9 2018-06-17
  • 打赏
  • 举报
回复
引用 1 楼 yuankaiwsl 的回复:
把SystemService.GetAsyncKeyState(17) != 0之类定义一下变量看看真的是不是你所想象的
我调试的思路不就是直接把SystemService.GetAsyncKeyState(17)以对话框的形式输出了吗?

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧