flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved]WM_KEYDOWN VK_LCONTROL

Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 19 Mar 2017, 01:01
I'm learning winapi, and I need to get state of ctrl key, presset it currently or not.

I expected to receive VK_LCONTROL VK_RCONTROL messages for it (0xa2 0xa3), but instead I'm only getting VK_CONTROL (0x11). And as for alt, I'm not getting WM_KEYDOWN at all.

What's this about? So I have to use GetKeyState, instead of just waiting for WM_KEYDOWN?


Last edited by vivik on 19 Mar 2017, 10:12; edited 1 time in total
Post 19 Mar 2017, 01:01
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1626
Location: Toronto, Canada
AsmGuru62 19 Mar 2017, 03:05
From MSDN it looks like you need to wait for WM_KEYDOWN with VK_CONTROL and then detect L/R with GetKeyState():
Code:
if (msg == WM_KEYDOWN)
{
        if (wParam == VK_CONTROL)
        {
                if (GetKeyState (VK_LCONTROL) & 0x8000)
                {
                        // LEFT Control Key
                }
                else
                {
                        // RIGHT Control Key
                }
        }
}
    
Post 19 Mar 2017, 03:05
View user's profile Send private message Send e-mail Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 790
Location: Adelaide
sinsi 19 Mar 2017, 04:11
Maybe bit 24 of lParam?
Quote:
Indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.

Apparently VK_LCONTROL VK_RCONTROL are only used for GetKeyState and GetAsyncKeyState.
Post 19 Mar 2017, 04:11
View user's profile Send private message Reply with quote
guignol



Joined: 06 Dec 2008
Posts: 763
guignol 19 Mar 2017, 05:32
VK_ is a key number
Post 19 Mar 2017, 05:32
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
bitRAKE 19 Mar 2017, 05:46
Have you tried any of those Message Hook/Spy tools? They are very useful for figuring out what Windows is doing.

Spy++ comes with Visual Studio, but other similar programs exist.
http://mdb-blog.blogspot.com/2010/11/microsoft-spy-or-spyxx-for-download.html

http://www.catch22.net/software/winspy-17

http://windowdetective.sourceforge.net/


Description: left alt, left ctl, right alt*, right ctl*, left shift, right shift
*( fExtended flags means right. )
Filesize: 37.83 KB
Viewed: 5826 Time(s)

Capture.PNG



_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 19 Mar 2017, 05:46
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 19 Mar 2017, 08:38
@bitRAKE
Third link worked, thank you! First didn't show messages for my app for some reason (worked fine for others), and second only shows information about window itself.

I also fixed some other bug with it (I was getting too much WM_PAINT), really usefull.

So alt received not with WM_KEYDOWN, but with WM_SYSKEYDOWN. According to this link https://msdn.microsoft.com/en-us/library/windows/desktop/gg153546(v=vs.85).aspx the only SYSKEYDOWN keys are alt and f10, and I must to pass them to DefWindowProc in order to not break anything. Weird. But now I understand why walking doesn't work in half life 2 on windows 7, as a bonus.

As of VK_LCONTROL VK_RCONTROL, looks like they are indeed for GetKeyState() only. Thanks, everyone!
Post 19 Mar 2017, 08:38
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.