Forum > TAChart

ChartToolset detect keys pressed

(1/2) > >>

How can I detect which key was pressed in a "ChartToolset", e.g. in event "ChartToolset1ZoomDragTool1AfterKeyDown"? Help would be very much appreciated.

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?

I mean any key as the event is fired by pressing any key like ESC.

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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TChartTool.KeyDown(APoint: TPoint);begin  Unused(APoint);  if EscapeCancels and ((GetKeyState(VK_ESCAPE) and $8000) <> 0) then    Cancel;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?

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!!!


[0] Message Index

[#] Next page

Go to full version