KeyDown routine and Ctrl+Q

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

KeyDown routine and Ctrl+Q

Jürgen Hestermann
I use a KEYDOWN routine in my main TFORM to check for the key Ctrl+Q:

-----------------------------------------------------------------
procedure TForm1.FormKeyDown(Sender : TObject;
                          var Key    : Word;
                              Shift  : TShiftState);
begin // TForm1.FormKeyDown
case key of
    VK_Q :
       begin
       if Shift=[ssCtrl] then
          begin
          ....
-----------------------------------------------------------------

But when I type "Ctrl+Q" then "Key" is 17 instead of VK_Q (81).

If I now use 17 to trigger the "Q" key, then it is also triggered
when I just type the Ctrl-key (without any other key)!

This is all a bit weird.
How can I detect that "Ctrl+Q" is pressed without
getting fooled by any other key?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KeyDown routine and Ctrl+Q

Bart-48
On 2/8/17, Jürgen Hestermann <[hidden email]> wrote:

>
> But when I type "Ctrl+Q" then "Key" is 17 instead of VK_Q (81).

I get $51 for the key when I press Ctrl+Q (Win32).

Bart
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KeyDown routine and Ctrl+Q

Vojtěch Čihák
In reply to this post by Jürgen Hestermann

Hi,

when you press CTRL+Q you will obtain two OnKeyDown events. The first with Key=17 (it is CTRL) and the second with Key=81 (Q). Both events will have ssCtrl in Shift.

 

V.

______________________________________________________________
> Od: Jürgen Hestermann <[hidden email]>
> Komu: FPC-Pascal users discussions <[hidden email]>
> Datum: 08.02.2017 22:12
> Předmět: [fpc-pascal] KeyDown routine and Ctrl+Q
>

I use a KEYDOWN routine in my main TFORM to check for the key Ctrl+Q:

-----------------------------------------------------------------
procedure TForm1.FormKeyDown(Sender : TObject;
                         var Key    : Word;
                             Shift  : TShiftState);
begin // TForm1.FormKeyDown
case key of
   VK_Q :
      begin
      if Shift=[ssCtrl] then
         begin
         ....
-----------------------------------------------------------------

But when I type "Ctrl+Q" then "Key" is 17 instead of VK_Q (81).

If I now use 17 to trigger the "Q" key, then it is also triggered
when I just type the Ctrl-key (without any other key)!

This is all a bit weird.
How can I detect that "Ctrl+Q" is pressed without
getting fooled by any other key?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KeyDown routine and Ctrl+Q

Mark Morgan Lloyd-5
In reply to this post by Jürgen Hestermann
On 08/02/17 21:30, Jürgen Hestermann wrote:

> I use a KEYDOWN routine in my main TFORM to check for the key Ctrl+Q:
>
> -----------------------------------------------------------------
> procedure TForm1.FormKeyDown(Sender : TObject;
>                          var Key    : Word;
>                              Shift  : TShiftState);
> begin // TForm1.FormKeyDown
> case key of
>    VK_Q :
>       begin
>       if Shift=[ssCtrl] then
>          begin
>          ....
> -----------------------------------------------------------------
>
> But when I type "Ctrl+Q" then "Key" is 17 instead of VK_Q (81).
>
> If I now use 17 to trigger the "Q" key, then it is also triggered
> when I just type the Ctrl-key (without any other key)!
>
> This is all a bit weird.
> How can I detect that "Ctrl+Q" is pressed without
> getting fooled by any other key?

Watch out for operating systems which still handle ^S ^Q and possibly ^P
specially. I was painfully reminded of this the other day when I hit ^S
in an SSH session and everything ground to a halt.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KeyDown routine and Ctrl+Q

Jürgen Hestermann
In reply to this post by Vojtěch Čihák
Am 2017-02-08 um 23:26 schrieb Vojtěch Čihák:
 > when you press CTRL+Q you will obtain two OnKeyDown events. The first with Key=17 (it is CTRL) and the second with Key=81 (Q). Both events will have ssCtrl in Shift.

Yep, it makes sense for OnKeyDown.
Thanks for the explanation.

I don't know why I was under the impression that it
did not work. It works now just the way I coded
it from start. I may have got bewildered by some other
problem I got with my code...

BTW:
When Ctrl is pressed, then Shift is empty (which is expected).
Only on the second key Q Shift contains ssCtrl.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KeyDown routine and Ctrl+Q

Vojtěch Čihák
In reply to this post by Vojtěch Čihák

Strange. I tested in Linux+Qt and in Delphi7 (under Wine) and both have ssCtrl in Shift when I press Ctrl (i.e. Key=17).

 

V.

______________________________________________________________
> Od: Jürgen Hestermann <[hidden email]>
> Komu: FPC-Pascal users discussions <[hidden email]>
> Datum: 09.02.2017 11:52
> Předmět: Re: [fpc-pascal] KeyDown routine and Ctrl+Q
>


BTW:
When Ctrl is pressed, then Shift is empty (which is expected).
Only on the second key Q Shift contains ssCtrl.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KeyDown routine and Ctrl+Q

Jürgen Hestermann
Am 2017-02-09 um 14:42 schrieb Vojtěch Čihák:

Strange. I tested in Linux+Qt and in Delphi7 (under Wine) and both have ssCtrl in Shift when I press Ctrl (i.e. Key=17).


Well, I looked at Shift in the debugger and I could swear that
it showed me an empty set [].
But now I can't reproduce it anymore and I always get [ssCtrl] too.
So you seem to be right that in both cases Shift=[ssCtrl].



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Loading...