Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6743551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:58:28+00:00 2026-05-26T11:58:28+00:00

I investigated GetAsyncKeyState after seeing it in a code example on how to make

  • 0

I investigated GetAsyncKeyState after seeing it in a code example on how to make a fictional character move on the screen through the WASD keys.

I read this on its MSDN page:

Return value

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.

I’m having trouble understanding the structure of the return value:

It says the type is short, so through it I suppose you could represent the number zero, in binary, as 0000000000000000, or in hex as 0x0000 (since as far as I know one hex digit represents four binary digits).

The description says that the most significant bit should be set when the key is pressed. That makes me think that, if said bit was set, the number would appear like this:

1000000000000000

To make better use of it in my program, I shortened it by translating it to hex, resulting into:

0x8000

Because 8 in hex should correspond to 1000 in binary.

When I saw that said mechanism was not working in my program (doing GetAsyncKeyState(chr) == 0x8000 would always yield false, no matter if the key was pressed or not) I took one more look to the original example I saw the function employed in first. There, the return value was being compared with the number -32767, which, when quickly translated to hex using the Windows calculator, results into the value 0xFFFFFFFFFFFF8001. Now, don’t mind the last hex digit (1) because that’s the bit used to check whether the least significant bit is also active, but I don’t want that in my case.

The things that I can’t understand here are the following:

  1. Why, if one hex digit represents four binary digits, and the output value of the function is a short (two bytes), here the number is represented by sixteen hex digits? Aren’t those eight bytes?
  2. The description of the return value said that the most significant bit would be set to 1 if the key was being pressed, and that led me to believe that the number would look like 1000000000000000, not 0000000000001000. What am I missing here?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:58:28+00:00Added an answer on May 26, 2026 at 11:58 am
    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have investigated getting the source code of a method if it exists as
I got a question how Monitor.Enter works. I investigated .net framework source code, and
I have now investigated the 400 - BadRequest code for the last two hours.
I've investigated several C# DLL's and have not found any that work especially well.
I'm starting to investigate T4 for Code Generation. I get that you have a
When I worked on asp.net mvc web site project, I investigated different approaches for
I'm principally interested in case studies on code metrics, relating code readability to defect
When I run following code: public ActionResult Complete() { try { VeriTabanDataContext db =
I was searching an MS-SQL Server 2005 database to make sure that a certain
I've investigated for a while how to use such combimation as IdP (ADFS 2.0),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.