ruby - 什么是 GetAsyncKeyState 返回值?

标签 ruby winapi

我试图在我正在处理的项目中使用 GetAsyncKeyState。唯一的问题是我不知道它返回什么值,也不知道如何检查它。根据MSNdocumentation :

Type: SHORT

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, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. However, you should not rely on this last behavior; for more information, see the Remarks.

我知道 SHORT 类型是一个数字,但我在 StackOverflow 和互联网上看到了很多不同的答案,但是当 GetAsyncKeyState 的计算结果为 true 时,它​​的返回值是多少?返回 0 还是 0x8001?

最佳答案

返回值可以是 4 个可能值之一:

  • 0x0000
  • 0x0001
  • 0x8000
  • 0x8001

使用 & 0x8000 (或者 < 0 因为 SHORT 是有符号类型)检查“最高有效位是否设置”(这使得有符号类型为负)。

使用 & 0x0001检查“最低有效位是否已设置”。

关于ruby - 什么是 GetAsyncKeyState 返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53249586/

相关文章:

delphi - 如何查询 "Size on disk"文件信息?

c++ - RegisterRawInputDevices函数使用

c++ - 如何将 WndProc 用作类函数

ruby - rdoc 和 md 有什么区别?

ruby - 如果哈希数组具有属性/值对,如何编写 rspec 测试

c++ - 如何正确销毁从另一个线程运行的窗口?

macos - 将 win32 MIDI SysEx 应用程序移植到 MacOSX

ruby - 两个连接表的续集模型

ruby - 如何更改 Docker 镜像中的 Ruby 版本(将 2.2.0 替换为 2.0.0 )

php - 为什么 ruby​​ 的 to_json 会破坏嵌入式 javascript?