Recent

Author Topic: ChartToolset detect keys pressed  (Read 1564 times)

Firebird

  • New Member
  • *
  • Posts: 28
ChartToolset detect keys pressed
« on: February 10, 2024, 07:13:51 pm »
How can I detect which key was pressed in a "ChartToolset", e.g. in event "ChartToolset1ZoomDragTool1AfterKeyDown"? Help would be very much appreciated.

wp

  • Hero Member
  • *****
  • Posts: 13329
Re: ChartToolset detect keys pressed
« Reply #1 on: February 10, 2024, 10:14:19 pm »
What do you mean with "key"? An arbitrary key on the keyboard, or one of the keys listed in the Shift property of the tool?

Firebird

  • New Member
  • *
  • Posts: 28
Re: ChartToolset detect keys pressed
« Reply #2 on: February 11, 2024, 09:44:51 am »
I mean any key as the event is fired by pressing any key like ESC.

wp

  • Hero Member
  • *****
  • Posts: 13329
Re: ChartToolset detect keys pressed
« Reply #3 on: February 11, 2024, 12:27:22 pm »
I think that's not possible (at least not easily). The TChart component does not handle keyboard events in the same way as other components. What you see in the ESC key is a special handling for this particular key since the tool reads the keyboard by itself after the message loop:
Code: Pascal  [Select][+][-]
  1. procedure TChartTool.KeyDown(APoint: TPoint);
  2. begin
  3.   Unused(APoint);
  4.   if EscapeCancels and ((GetKeyState(VK_ESCAPE) and $8000) <> 0) then
  5.     Cancel;
  6. end;
But this happens only after the tool has been activated. And activation occurs when the conditions defined by the Shift enumerations have become true, for example a mouse click or pressing a special key such as CTRL. Standard keys are not listed here. I don't know whether this is an unavoidable requirement for the tools to work. But I think Alexander S. Klenin (the author of the ChartTools) did not want too much interaction with the keyboard. Because the chart must be focused in order to receive keyboard events. I do remember the annoying observation that my CTRL press was not noticed by the chart althought ssCTRL was listed among the tool's Shift values. Alexander then implemented the AutoFocus property of the chart which gives the chart the focus when the mouse moves over the chart - but this is even more annoying when you are typing something in a memo or an edit, ove the mouse over the chart and continue typing: these keys will be lost because they were sent to the focussed chart.

Why don't you catch the keypress in the form's keyboard events after setting its KeyPreview to true?

What do you want to achieve?

Firebird

  • New Member
  • *
  • Posts: 28
Re: ChartToolset detect keys pressed
« Reply #4 on: February 11, 2024, 07:40:13 pm »
Zoom and Pan are 2 operations which cannot be carried out at all times on my graph. They can only be selected from a mouse menu when certain conditions hold true. After either of them has been selected the mouse menu cannot be used any more before the operation (zoom, pan) is finished. I was looking for a simple means to cancel this state via the "ESC" key.
Your proposal using the KeyPreview of the form works perfect for me. Thank you very much!!!

wp

  • Hero Member
  • *****
  • Posts: 13329
Re: ChartToolset detect keys pressed
« Reply #5 on: February 11, 2024, 07:55:22 pm »
You want to abort a zoom/pan operations done by dragging the mouse? There's a built-in propery for this purpose: EscapeCancels

 

TinyPortal © 2005-2018