Confused by windows keyboard event lParamHow can I develop for iPhone using a Windows development machine?How can you find out which process is listening on a port on Windows?Is there an equivalent of 'which' on the Windows command line?PeekMessage problemHow do I install pip on Windows?WndProc assignment issueSubclassing an edit text control to accept lowercase characters when shift is pressedWhat is the HWND parameter in the Windows Procedure Functions?Is there one Windows System Message Queue or Multiple?How do you send keystrokes to an inactive window?

The Planck constant for mathematicians

Asking students to define "unique"

What officially disallows US presidents from driving?

Is there any reason to concentrate on the Thunderous Smite spell after using its effects?

Are space camera sensors usually round, or square?

POSIX compatible way to get user name associated with a user ID

If I want an interpretable model, are there methods other than Linear Regression?

Why is the Digital 0 not 0V in computer systems?

Why is my fire extinguisher emptied after one use?

Bit one of the Intel 8080's Flags register

Should I leave the first authorship of our paper to the student who did the project whereas I solved it?

What jurisdiction do Scottish courts have over the Westminster parliament?

Where to disclose a zero day vulnerability

Double it your way

Diffraction of a wave passing through double slits

What's 待ってるから mean?

Is the Dodge action perceptible to other characters?

What makes a smart phone "kosher"?

What does a Light weapon mean mechanically?

Parallel resistance in electric circuits

Can you add polynomial terms to multiple linear regression?

Sort files in a given folders and provide as a list

What are uses of the byte after BRK instruction on 6502?

Why some files are not movable in Windows 10



Confused by windows keyboard event lParam


How can I develop for iPhone using a Windows development machine?How can you find out which process is listening on a port on Windows?Is there an equivalent of 'which' on the Windows command line?PeekMessage problemHow do I install pip on Windows?WndProc assignment issueSubclassing an edit text control to accept lowercase characters when shift is pressedWhat is the HWND parameter in the Windows Procedure Functions?Is there one Windows System Message Queue or Multiple?How do you send keystrokes to an inactive window?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Part of the code:



LRESULT CALLBACK WindowProc(
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam)
...
switch(uMsg)
...
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP:

uint8_t VKCODE = wParam;
bool WasDown = ((lParam & (1<<30)) != 0);
bool IsDown = ((lParam & (1<<31)) == 0);
if(WasDown != IsDown)

if(VKCode == 'W')

OutputDebugStringA("W: ");
if(WasDown)

OutputDebugStringA("WasDown ");

if(IsDown)

OutputDebugStringA("IsDown ");

OutputDebugStringA("n");

else if(VKCode == 'A')

OutputDebugStringA("An");

...

break;
...

...



1) First, when I press 'A', will always output 2 'A's.



2) Second, according to this page:
https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-keyup




30 The previous key state. The value is always 1 for a WM_KEYUP message.



31 The transition state. The value is always 1 for a WM_KEYUP message.




then (lParam & (1<<31)) will always be non-zero, so IsDown will always be false, but when I press(hit and release) 'W' it will output:



IsDown
WasDown


How come it will output "IsDown" if bool IsDown is always false?



3) If I comment out 3 cases before WM_KEYUP like this:



// case WM_SYSKEYDOWN:
// case WM_SYSKEYUP:
// case WM_KEYDOWN:


then when I press 'A' will only output one 'A', when I press 'W' will only output "WasDown", never "IsDown". I didn't wrote any code under previous 3 cases before comment them out anyway, what happened?



BTW, I'm following this video if anyone wants to see the full code:



https://www.youtube.com/watch?v=J3y1x54vyIQ










share|improve this question





















  • 5





    From what you say under point 3 it sounds like you don't quite understand how case statements work in C/C++. The way you have your code structured, all four messages will be processed the same way. As far as #2 goes, bit 30 and 31 are always 1 for WM_KEYUP but for WM_KEYDOWN bit 30 can be 0 or 1 and bit 31 is always 0.

    – Jonathan Potter
    Mar 28 at 10:38











  • @JonathanPotter So when I press a key, WindowProc process the message for WM_KEYDOWN and WM_KEYUP with the same block of code under case KEY_UP?

    – oNion
    Mar 28 at 10:44






  • 3





    Yes, because when you have multiple case statements without a break in between them, control will flow through them from the matching case to the next break.

    – Jonathan Potter
    Mar 28 at 10:48







  • 1





    cboard.cprogramming.com/cplusplus-programming/…

    – David Heffernan
    Mar 28 at 10:52






  • 1





    @oNion general advice: before trying to make Windows programs you should get familiar with the basics of the C language.

    – Jabberwocky
    Mar 28 at 12:41

















0















Part of the code:



LRESULT CALLBACK WindowProc(
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam)
...
switch(uMsg)
...
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP:

uint8_t VKCODE = wParam;
bool WasDown = ((lParam & (1<<30)) != 0);
bool IsDown = ((lParam & (1<<31)) == 0);
if(WasDown != IsDown)

if(VKCode == 'W')

OutputDebugStringA("W: ");
if(WasDown)

OutputDebugStringA("WasDown ");

if(IsDown)

OutputDebugStringA("IsDown ");

OutputDebugStringA("n");

else if(VKCode == 'A')

OutputDebugStringA("An");

...

break;
...

...



1) First, when I press 'A', will always output 2 'A's.



2) Second, according to this page:
https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-keyup




30 The previous key state. The value is always 1 for a WM_KEYUP message.



31 The transition state. The value is always 1 for a WM_KEYUP message.




then (lParam & (1<<31)) will always be non-zero, so IsDown will always be false, but when I press(hit and release) 'W' it will output:



IsDown
WasDown


How come it will output "IsDown" if bool IsDown is always false?



3) If I comment out 3 cases before WM_KEYUP like this:



// case WM_SYSKEYDOWN:
// case WM_SYSKEYUP:
// case WM_KEYDOWN:


then when I press 'A' will only output one 'A', when I press 'W' will only output "WasDown", never "IsDown". I didn't wrote any code under previous 3 cases before comment them out anyway, what happened?



BTW, I'm following this video if anyone wants to see the full code:



https://www.youtube.com/watch?v=J3y1x54vyIQ










share|improve this question





















  • 5





    From what you say under point 3 it sounds like you don't quite understand how case statements work in C/C++. The way you have your code structured, all four messages will be processed the same way. As far as #2 goes, bit 30 and 31 are always 1 for WM_KEYUP but for WM_KEYDOWN bit 30 can be 0 or 1 and bit 31 is always 0.

    – Jonathan Potter
    Mar 28 at 10:38











  • @JonathanPotter So when I press a key, WindowProc process the message for WM_KEYDOWN and WM_KEYUP with the same block of code under case KEY_UP?

    – oNion
    Mar 28 at 10:44






  • 3





    Yes, because when you have multiple case statements without a break in between them, control will flow through them from the matching case to the next break.

    – Jonathan Potter
    Mar 28 at 10:48







  • 1





    cboard.cprogramming.com/cplusplus-programming/…

    – David Heffernan
    Mar 28 at 10:52






  • 1





    @oNion general advice: before trying to make Windows programs you should get familiar with the basics of the C language.

    – Jabberwocky
    Mar 28 at 12:41













0












0








0








Part of the code:



LRESULT CALLBACK WindowProc(
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam)
...
switch(uMsg)
...
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP:

uint8_t VKCODE = wParam;
bool WasDown = ((lParam & (1<<30)) != 0);
bool IsDown = ((lParam & (1<<31)) == 0);
if(WasDown != IsDown)

if(VKCode == 'W')

OutputDebugStringA("W: ");
if(WasDown)

OutputDebugStringA("WasDown ");

if(IsDown)

OutputDebugStringA("IsDown ");

OutputDebugStringA("n");

else if(VKCode == 'A')

OutputDebugStringA("An");

...

break;
...

...



1) First, when I press 'A', will always output 2 'A's.



2) Second, according to this page:
https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-keyup




30 The previous key state. The value is always 1 for a WM_KEYUP message.



31 The transition state. The value is always 1 for a WM_KEYUP message.




then (lParam & (1<<31)) will always be non-zero, so IsDown will always be false, but when I press(hit and release) 'W' it will output:



IsDown
WasDown


How come it will output "IsDown" if bool IsDown is always false?



3) If I comment out 3 cases before WM_KEYUP like this:



// case WM_SYSKEYDOWN:
// case WM_SYSKEYUP:
// case WM_KEYDOWN:


then when I press 'A' will only output one 'A', when I press 'W' will only output "WasDown", never "IsDown". I didn't wrote any code under previous 3 cases before comment them out anyway, what happened?



BTW, I'm following this video if anyone wants to see the full code:



https://www.youtube.com/watch?v=J3y1x54vyIQ










share|improve this question
















Part of the code:



LRESULT CALLBACK WindowProc(
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam)
...
switch(uMsg)
...
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP:

uint8_t VKCODE = wParam;
bool WasDown = ((lParam & (1<<30)) != 0);
bool IsDown = ((lParam & (1<<31)) == 0);
if(WasDown != IsDown)

if(VKCode == 'W')

OutputDebugStringA("W: ");
if(WasDown)

OutputDebugStringA("WasDown ");

if(IsDown)

OutputDebugStringA("IsDown ");

OutputDebugStringA("n");

else if(VKCode == 'A')

OutputDebugStringA("An");

...

break;
...

...



1) First, when I press 'A', will always output 2 'A's.



2) Second, according to this page:
https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-keyup




30 The previous key state. The value is always 1 for a WM_KEYUP message.



31 The transition state. The value is always 1 for a WM_KEYUP message.




then (lParam & (1<<31)) will always be non-zero, so IsDown will always be false, but when I press(hit and release) 'W' it will output:



IsDown
WasDown


How come it will output "IsDown" if bool IsDown is always false?



3) If I comment out 3 cases before WM_KEYUP like this:



// case WM_SYSKEYDOWN:
// case WM_SYSKEYUP:
// case WM_KEYDOWN:


then when I press 'A' will only output one 'A', when I press 'W' will only output "WasDown", never "IsDown". I didn't wrote any code under previous 3 cases before comment them out anyway, what happened?



BTW, I'm following this video if anyone wants to see the full code:



https://www.youtube.com/watch?v=J3y1x54vyIQ







c++ windows winapi windows-messages






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 10:31







oNion

















asked Mar 28 at 10:23









oNionoNion

451 silver badge8 bronze badges




451 silver badge8 bronze badges










  • 5





    From what you say under point 3 it sounds like you don't quite understand how case statements work in C/C++. The way you have your code structured, all four messages will be processed the same way. As far as #2 goes, bit 30 and 31 are always 1 for WM_KEYUP but for WM_KEYDOWN bit 30 can be 0 or 1 and bit 31 is always 0.

    – Jonathan Potter
    Mar 28 at 10:38











  • @JonathanPotter So when I press a key, WindowProc process the message for WM_KEYDOWN and WM_KEYUP with the same block of code under case KEY_UP?

    – oNion
    Mar 28 at 10:44






  • 3





    Yes, because when you have multiple case statements without a break in between them, control will flow through them from the matching case to the next break.

    – Jonathan Potter
    Mar 28 at 10:48







  • 1





    cboard.cprogramming.com/cplusplus-programming/…

    – David Heffernan
    Mar 28 at 10:52






  • 1





    @oNion general advice: before trying to make Windows programs you should get familiar with the basics of the C language.

    – Jabberwocky
    Mar 28 at 12:41












  • 5





    From what you say under point 3 it sounds like you don't quite understand how case statements work in C/C++. The way you have your code structured, all four messages will be processed the same way. As far as #2 goes, bit 30 and 31 are always 1 for WM_KEYUP but for WM_KEYDOWN bit 30 can be 0 or 1 and bit 31 is always 0.

    – Jonathan Potter
    Mar 28 at 10:38











  • @JonathanPotter So when I press a key, WindowProc process the message for WM_KEYDOWN and WM_KEYUP with the same block of code under case KEY_UP?

    – oNion
    Mar 28 at 10:44






  • 3





    Yes, because when you have multiple case statements without a break in between them, control will flow through them from the matching case to the next break.

    – Jonathan Potter
    Mar 28 at 10:48







  • 1





    cboard.cprogramming.com/cplusplus-programming/…

    – David Heffernan
    Mar 28 at 10:52






  • 1





    @oNion general advice: before trying to make Windows programs you should get familiar with the basics of the C language.

    – Jabberwocky
    Mar 28 at 12:41







5




5





From what you say under point 3 it sounds like you don't quite understand how case statements work in C/C++. The way you have your code structured, all four messages will be processed the same way. As far as #2 goes, bit 30 and 31 are always 1 for WM_KEYUP but for WM_KEYDOWN bit 30 can be 0 or 1 and bit 31 is always 0.

– Jonathan Potter
Mar 28 at 10:38





From what you say under point 3 it sounds like you don't quite understand how case statements work in C/C++. The way you have your code structured, all four messages will be processed the same way. As far as #2 goes, bit 30 and 31 are always 1 for WM_KEYUP but for WM_KEYDOWN bit 30 can be 0 or 1 and bit 31 is always 0.

– Jonathan Potter
Mar 28 at 10:38













@JonathanPotter So when I press a key, WindowProc process the message for WM_KEYDOWN and WM_KEYUP with the same block of code under case KEY_UP?

– oNion
Mar 28 at 10:44





@JonathanPotter So when I press a key, WindowProc process the message for WM_KEYDOWN and WM_KEYUP with the same block of code under case KEY_UP?

– oNion
Mar 28 at 10:44




3




3





Yes, because when you have multiple case statements without a break in between them, control will flow through them from the matching case to the next break.

– Jonathan Potter
Mar 28 at 10:48






Yes, because when you have multiple case statements without a break in between them, control will flow through them from the matching case to the next break.

– Jonathan Potter
Mar 28 at 10:48





1




1





cboard.cprogramming.com/cplusplus-programming/…

– David Heffernan
Mar 28 at 10:52





cboard.cprogramming.com/cplusplus-programming/…

– David Heffernan
Mar 28 at 10:52




1




1





@oNion general advice: before trying to make Windows programs you should get familiar with the basics of the C language.

– Jabberwocky
Mar 28 at 12:41





@oNion general advice: before trying to make Windows programs you should get familiar with the basics of the C language.

– Jabberwocky
Mar 28 at 12:41












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395224%2fconfused-by-windows-keyboard-event-lparam%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395224%2fconfused-by-windows-keyboard-event-lparam%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript