问题描述
限时送ChatGPT账号..我试图通过简单的按键操作找到对这些数字及其含义的任何合乎逻辑的解释.GetAsyncKeyState(VK_SHIFT) &0x8000;
.
I am trying to find any logical explanation to these numbers and their meaning in the simple action of pressing a key.
GetAsyncKeyState(VK_SHIFT) & 0x8000;
.
还有哪些值可以代替 0x8000
使用,它们与按键有什么关系?
What other values can be used instead of 0x8000
and what do they have to do with pressing a key ?
推荐答案
GetAsyncKeyState 根据文档返回
GetAsyncKeyState according to the documentation returns
如果函数成功,则返回值指定自上次调用 GetAsyncKeyState 以来是否按下了该键,以及该键当前是向上还是向下.如果设置了最高有效位,则密钥为 down ...
If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down ...
如果你把数字 0x8000 用二进制写出来就是
If you take the number 0x8000 and write it out in binary it will be
10000000 00000000 00000000 00000000
最左边的那一位称为最重要的位"
That bit on the far left is called "the most significant bit"
&
运算符的作用是执行按位与操作,这意味着 &
两侧只有 1
代码>将在结果中.
What the the &
operator does is it does a bitwise AND which means only bits that are a 1
in both sides of the &
will be in the result.
做<代码>&0x8000 是一种屏蔽(忽略)除最高有效位之外的所有位的方法.然后,您可以检查此操作的结果是 != 0
,这将根据您传递给函数的键是否被按下而返回 true 或 false.
Doing & 0x8000
is a way to mask off (ignore) all of the bits except for the most significant bit. You can then check the result of this operation is != 0
and that will return true or false depending on if the key you passed in to the function was pressed down.
由于您的代码被标记为 c# 但此函数来自本机 Windows 函数,因此您可能看到的示例可能看起来像
As your code is tagged c# but this function is from the native windows functions the example you may have seen this from may have just looked like
if (GetAsyncKeyState(VK_SHIFT) & 0x8000) {
...
}
在 C++ 中,if 语句中对 != 0
进行了隐式检查,因此任何非零值都被视为真.
in C++ there is a implicit check of != 0
in the if statement so any non zero value is treated as true.
这篇关于代码 GetAsyncKeyState(VK_SHIFT) & 中的这些数字是什么?0x8000 ?它们是必不可少的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论