GetAsyncKeyState's return values don't seem to correspond with the description

自古美人都是妖i 提交于 2019-12-06 05:35:38
GetAsyncKeyState(chr) == 0x8000

This is incorrect check. Use:

!!(GetAsyncKeyState(chr) & 0x8000)

to see if the most-significant bit is set.

The value 0xFFFFFFFFFFFF8001 doesn't correspond to the actual returned value from GetAsyncKeyState. Windows calculator doesn't know the size of the value returned from GetAsyncKeyState, so it assumes you're working with 64-bit number. You can override it in its settings.

1 - returned value is SHORT, which is 16 bits = 2 bytes.

2 - most significant bit is the 15th, as the value is signed if you cast it to 32-bit INT, 16-bit 1000 0000 value would become 1111 1111 1000 0000 (in 64-bit world the conversion would be 1000 0000 -> 1111 1111 1111 1111 - 1111 1111 1000 0000). If you want to just test the most significant bit of the signed integer value, just compare it to zero:

if(GetAsyncKeyState(...) < 0)
{
  // Hey, MSB is set here!
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!