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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현