Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-04

how to handle Shift=[ssCtrl]

9 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

FreeMan

fpc r30400 lazarus r48585 yosemite qt x64

procedure TFRM_.TLabel1_MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X  , Y: Integer);
begin
if(Button=mbRight)then begin
   if Shift=[ssCtrl] then begin
    ShowMessage('ctrl key pressed :');
   end;
end;
end;

while debuging, move mouse on "Shift" and hint show values is 128, ssCtrl values is SSCTRL. and its not aqual, I mean I can not handle ctrl
+ right click on Tlabel.
command key = 4
ssctrl =128
ssAlt = 2
ssShift = 1
ssctrl + ssAlt = 130
some shift values from hint

Reply by email

Vojtěch Čihák
to FreeMan

Hi,
?
You must use:
if ssCtrl in Shift then ...
instead.
?
That's because mouse-buttons are in Shift too. If you do Ctrl+right-click, then Shift=[ssRight, ssCtrl]. And possibly something else (ssCaps). ?
V.
______________________________________________________________

Show quoted text 5 lines
Od: FreeMan Komu: Lazarus mail list Datum: 02.04.2015 13:37 P?edm?t: [Lazarus] how to handle Shift=[ssCtrl]

fpc r30400 lazarus r48585 yosemite qt x64

procedure TFRM_.TLabel1_MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X ?, Y: Integer);
begin
if(Button=mbRight)then begin
 ? if Shift=[ssCtrl] then begin
 ? ?ShowMessage('ctrl key pressed :');
 ? end;
end;
end;

while debuging, move mouse on "Shift" and hint show values is 128, ssCtrl values is SSCTRL. and its not aqual, I mean I can not handle ctrl
+ right click on Tlabel.
command key = 4
ssctrl =128
ssAlt = 2
ssShift = 1
ssctrl + ssAlt = 130
some shift values from hint

Reply by email

FreeMan
to Vojtěch Čihák

in mouseup tnotifyevent,
shift parameter has not value of mouse button, values is zero. Button parameter has value, mbRight etc.
if ssCtrl in Shift then... has same result, I mean not handle ctrl or other keys(ssalt, ssshift)

Vojt?ch ?ih?k wrote 15 lines
Hi, You must use: if ssCtrl in Shift then ... instead. That's because mouse-buttons are in Shift too. If you do Ctrl+right-click, then Shift=[ssRight, ssCtrl]. And possibly something else (ssCaps). V.

Reply by email

Graeme Geldenhuys
to Vojtěch Čihák: ? You must use: if ssCtrl in Shift then ... instead. ? That's because mouse-buttons are…
Vojt?ch ?ih?k wrote
if ssCtrl in Shift then ... instead.

It depends on how precise you want to be. Do you want that if statement to execute even if Ctrl+Shift is pressed, or _only_ when Shift is pressed?

To get ONLY the specific modifier key, then you need to mask the result. For example:

procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
  if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssShift] then
    ShowMessage('really, only Shift was pressed');
  if Shift * [ssShift,ssAlt,ssCtrl] = [ssShift,ssCtrl] then
    ShowMessage('Only Shift+Ctrl was pressed');
  if ssShift in Shift then
    ShowMessage('Shift could have been pressed with ssAlt for example');
end;

The last if statement will trigger if you pressed Shift, or Shift+Ctrl, or Shift+Alt, or Shift+Ctrl+Alt

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

FreeMan
to Graeme Geldenhuys: It depends on how precise you want to be. Do you want that if statement to execute even…

Thank you Graeme,
Yes your code is working and hold ssShift, just change ssShift to ssCtrl, and not work, I mean not show any message. What is your test system ? I wrote in first message, yosemite qt x64.

      if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssCtrl] then
        ShowMessage('really, only Ctrl was pressed');
      if Shift * [ssShift,ssAlt,ssCtrl] = [ssShift,ssCtrl] then
        ShowMessage('Only Shift+Ctrl was pressed');
      if ssCtrl in Shift then
        ShowMessage('Shift could have been pressed with ssctrl for
example');
Graeme Geldenhuys wrote 6 lines
if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssShift] then ShowMessage('really, only Shift was pressed'); if Shift * [ssShift,ssAlt,ssCtrl] = [ssShift,ssCtrl] then ShowMessage('Only Shift+Ctrl was pressed'); if ssShift in Shift then ShowMessage('Shift could have been pressed with ssAlt for example');

Reply by email

Graeme Geldenhuys
to FreeMan
FreeMan wrote
Yes your code is working and hold ssShift, just change ssShift to ssCtrl, and not work, I mean not show any message.

I tested here by changing ssShift to ssCtrl and it works perfectly.

  if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssCtrl] then
    ShowMessage('really, only Ctrl was pressed');
  if Shift * [ssShift,ssAlt,ssCtrl] = [ssShift,ssCtrl] then
    ShowMessage('Only Shift+Ctrl was pressed');
  if ssCtrl in Shift then
    ShowMessage('Ctrl could have been pressed with ssAlt or ssShift for
example');
What is your test system ?

64-bit FreeBSD with LCL-GTK2

I wrote in first message, yosemite qt x64.

If it doesn't work on your system, then it must be another bug in LCL. You should then file a bug report on Mantis. I suggest you also supply the test code above.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

JuuS
to FreeMan: Yes your code is working and hold ssShift, just change ssShift to ssCtrl, and not work, I…
FreeMan wrote
Thank you Graeme, Yes your code is working and hold ssShift, just change ssShift to ssCtrl, and not work, I mean not show any message. What is your test system ? I wrote in first message, yosemite qt x64.

Not sure if anyone already mentioned this but is the form's KeyPreview property set to true?

Show quoted text 25 lines
if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssCtrl] then ShowMessage('really, only Ctrl was pressed'); if Shift * [ssShift,ssAlt,ssCtrl] = [ssShift,ssCtrl] then ShowMessage('Only Shift+Ctrl was pressed'); if ssCtrl in Shift then ShowMessage('Shift could have been pressed with ssctrl for example'); On 2.04.2015 15:39, Graeme Geldenhuys wrote: > if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssShift] then > ShowMessage('really, only Shift was pressed'); > if Shift * [ssShift,ssAlt,ssCtrl] = [ssShift,ssCtrl] then > ShowMessage('Only Shift+Ctrl was pressed'); > if ssShift in Shift then > ShowMessage('Shift could have been pressed with ssAlt for example'); -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

FreeMan
to Graeme Geldenhuys: I tested here by changing ssShift to ssCtrl and it works perfectly. if…

constant name are wrong I think,
ssMeta -> ctrl key
ssCtrl -> cmd (command) key
fpc r30400 lazarus r48594 on yosemite qt x64

      if Shift * [ssShift, ssAlt, ssCtrl, ssMeta] = [ssCtrl]then
ShowMessage('ssCtrl(command key) pressed');
      if Shift * [ssShift, ssAlt, ssCtrl, ssMeta] = [ssMeta]then
ShowMessage('ssMeta(ctrl key) pressed');
      if Shift * [ssShift, ssAlt, ssCtrl, ssMeta] = [ssMeta,ssShift]then
ShowMessage('ssShift + ssMeta(ctrl key) pressed');
      if Shift * [ssShift, ssAlt, ssCtrl, ssMeta] = [ssCtrl,ssAlt]then
ShowMessage('ssAlt + ssCtrl(command key) pressed');
Graeme Geldenhuys wrote 29 lines
On 2015-04-02 15:33, FreeMan wrote: > Yes your code is working and hold ssShift, just change ssShift to > ssCtrl, and not work, I mean not show any message. I tested here by changing ssShift to ssCtrl and it works perfectly. if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssCtrl] then ShowMessage('really, only Ctrl was pressed'); if Shift * [ssShift,ssAlt,ssCtrl] = [ssShift,ssCtrl] then ShowMessage('Only Shift+Ctrl was pressed'); if ssCtrl in Shift then ShowMessage('Ctrl could have been pressed with ssAlt or ssShift for example'); > What is your test system ? 64-bit FreeBSD with LCL-GTK2 > I wrote in first message, yosemite qt x64. If it doesn't work on your system, then it must be another bug in LCL. You should then file a bug report on Mantis. I suggest you also supply the test code above. Regards, - Graeme -

Reply by email