Board index » delphi » Distinguishing between left and right shift/ctrl/alt keys

Distinguishing between left and right shift/ctrl/alt keys

I want my programme to be able to distinguish between the leftmost
shift-key and the right-most shift key.
The same goes for the ctrl and alt-keys.

I tried using getKeyState with the VK_LSHIFT and VK_RSHIFT parameters,
but they always return 0.

The programme is running on Windows 95, perhaps it is only possible on
Windows NT ???

 

Re:Distinguishing between left and right shift/ctrl/alt keys


I am pretty sure you need the international version of keyboard drivers
installed to do that. Use the keyboard applet in Control Panel.

Georg

In article <3635E64C.C6C4A...@skolemedia.dk>, Tommy Pedersen

Quote
<t...@skolemedia.dk> wrote:
> I want my programme to be able to distinguish between the leftmost
> shift-key and the right-most shift key.
> The same goes for the ctrl and alt-keys.

> I tried using getKeyState with the VK_LSHIFT and VK_RSHIFT parameters,
> but they always return 0.

> The programme is running on Windows 95, perhaps it is only possible on
> Windows NT ???

Re:Distinguishing between left and right shift/ctrl/alt keys


I am afraid that this won't make end users happy.

There has got to be some way to get the scancode and compare it to the value
of LSHIFT and RSHIFT.

Quote
Georg Pfaff wrote:
> I am pretty sure you need the international version of keyboard drivers
> installed to do that. Use the keyboard applet in Control Panel.

> Georg

> In article <3635E64C.C6C4A...@skolemedia.dk>, Tommy Pedersen
> <t...@skolemedia.dk> wrote:

> > I want my programme to be able to distinguish between the leftmost
> > shift-key and the right-most shift key.
> > The same goes for the ctrl and alt-keys.

> > I tried using getKeyState with the VK_LSHIFT and VK_RSHIFT parameters,
> > but they always return 0.

> > The programme is running on Windows 95, perhaps it is only possible on
> > Windows NT ???

Re:Distinguishing between left and right shift/ctrl/alt keys


Quote
> I want my programme to be able to distinguish between the leftmost
> shift-key and the right-most shift key.
> The same goes for the ctrl and alt-keys.

> I tried using getKeyState with the VK_LSHIFT and VK_RSHIFT parameters,
> but they always return 0.

> The programme is running on Windows 95, perhaps it is only possible on
> Windows NT ???

You guessed right. From the help for GetAsyncKeystate:

SHORT GetAsyncKeyState(

    int  vKey   // virtual-key code
   );  
Parameters

vKey

Specifies one of 256 possible virtual-key codes.  
Windows NT: You can use left- and right-distinguishing constants to specify
certain keys. See the Remarks section for further information.
Windows 95: Windows 95 does not support the left- and right-distinguishing
constants available on Windows NT.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Re:Distinguishing between left and right shift/ctrl/alt keys


Yes, but the help for GetKeyState does not specifically state that it only
works under NT.

But if the scancode is in the lParam of a WM_KEYDOWN message, how can it be
extracted??

Anyone ??

Quote
Peter Below wrote:
> > I want my programme to be able to distinguish between the leftmost
> > shift-key and the right-most shift key.
> > The same goes for the ctrl and alt-keys.

> > I tried using getKeyState with the VK_LSHIFT and VK_RSHIFT parameters,
> > but they always return 0.

> > The programme is running on Windows 95, perhaps it is only possible on
> > Windows NT ???

> You guessed right. From the help for GetAsyncKeystate:

> SHORT GetAsyncKeyState(

>     int  vKey   // virtual-key code
>    );
> Parameters

> vKey

> Specifies one of 256 possible virtual-key codes.
> Windows NT: You can use left- and right-distinguishing constants to specify
> certain keys. See the Remarks section for further information.
> Windows 95: Windows 95 does not support the left- and right-distinguishing
> constants available on Windows NT.

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitely requested!

Re:Distinguishing between left and right shift/ctrl/alt keys


Quote
In article <3636D473.92B87...@skolemedia.dk>, Tommy Pedersen wrote:
> But if the scancode is in the lParam of a WM_KEYDOWN message, how can it be
> extracted??

The scancode is simply Lobyte( HiWord( lparam )) but it does not help you.
Win95 generates the same scancode for left and right Shift etc..

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Re:Distinguishing between left and right shift/ctrl/alt keys


Perhaps using a hook, but I have not tested that.

Georg

In article <3635F466.194DE...@skolemedia.dk>, Tommy Pedersen

Quote
<t...@skolemedia.dk> wrote:
> There has got to be some way to get the scancode and compare it to the

> value of LSHIFT and RSHIFT

Re:Distinguishing between left and right shift/ctrl/alt keys


I tried your code and got two different scancodes 2A and 36.
So it works, but I have my doubts regarding the compatibility issues.

I have a table with scancodes for IBM and compatible keyboards. I have run the
programme on an IBM keyboard and a Microsoft Natural Keyboard with good results.
So let's hope that all other keyboards are IBM compatible.

But there may also be issues with the keyboard driver, who knows ???

Thank you for your help.

Quote
Peter Below wrote:
> In article <3636D473.92B87...@skolemedia.dk>, Tommy Pedersen wrote:
> > But if the scancode is in the lParam of a WM_KEYDOWN message, how can it be
> > extracted??

> The scancode is simply Lobyte( HiWord( lparam )) but it does not help you.
> Win95 generates the same scancode for left and right Shift etc..

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitely requested!

Re:Distinguishing between left and right shift/ctrl/alt keys


Quote
In article <36382E2C.F02DF...@skolemedia.dk>, Tommy Pedersen wrote:
> I tried your code and got two different scancodes 2A and 36.
> So it works, but I have my doubts regarding the compatibility issues.

It may indeed be keyboard-dependent. I remember trying it on my system and
got the same scancode for both keys. At least it would allow you to
distinguish the keys on *some* systems...

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Other Threads