Button.Click does not provide Shift, Ctrl & Alt-Key status

Created at 31 May 2024, 12:34
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
WO

wolters

Joined 25.03.2022

Button.Click does not provide Shift, Ctrl & Alt-Key status
31 May 2024, 12:34


Hi.

Because of the missing KeyUp-Event to maintain an internal state of the modifier keys Shift, Ctrl & Alt, I tried to use the Mouse-Up/Down-Events. 

It works fine inside the chart, but they are not triggered when hovering above a CustomControl (it seems as if “Mouse Leaves Chart Area”).

 

I try to use a Button.Click and depending on the modifier keys, I trigger different actions.
But in the ButtonClickEventArgs is no information about the Shift, Ctrl & Alt-Key status (as is in the ChartMouseEventArgs)

It seems to be impossible without getting real support of the underlying API to know if a modifier key is pressed or not.

Any idea on how to access the Shift, Ctrl & Alt-Key modifier status at any time (or at least at any mouse click event)? 
As I told before, there are some hacks on Windows, but coming to MacOS it seems to be impossible to get it to run.

 

;-(

Carsten


@wolters
Replies

tinaturner335
13 Jun 2024, 20:54 ( Updated at: 17 Jun 2024, 15:02 )

Hello @ undertale yellow

Instead of relying on the modifier key status directly, you can track the state of the modifier keys manually using event handlers.

Here's a general approach you can follow:

  1. Create variables to track the state of the modifier keys. For example, you can use boolean variables like isShiftPressed, isCtrlPressed, and isAltPressed.
  2. Register event handlers for the key events you want to track. In this case, you can register handlers for the KeyDown and KeyUp events.
  3. Inside the KeyDown event handler, check which modifier key was pressed and update the corresponding boolean variable accordingly.
  4. Inside the KeyUp event handler, reset the corresponding boolean variable for the released modifier key.
  5. Now, in your Button.Click event handler, you can check the values of the boolean variables to determine which modifier keys are pressed and trigger the appropriate actions accordingly.

@tinaturner335

wolters
14 Jun 2024, 06:31

RE: Button.Click does not provide Shift, Ctrl & Alt-Key status

tinaturner335 said: 

Hello, 

Instead of relying on the modifier key status directly, you can track the state of the modifier keys manually using event handlers.

Here's a general approach you can follow:

  1. Create variables to track the state of the modifier keys. For example, you can use boolean variables like isShiftPressed, isCtrlPressed, and isAltPressed.
  2. Register event handlers for the key events you want to track. In this case, you can register handlers for the KeyDown and KeyUp events.
  3. Inside the KeyDown event handler, check which modifier key was pressed and update the corresponding boolean variable accordingly.
  4. Inside the KeyUp event handler, reset the corresponding boolean variable for the released modifier key.
  5. Now, in your Button.Click event handler, you can check the values of the boolean variables to determine which modifier keys are pressed and trigger the appropriate actions accordingly.

 

Hi Tina,

thank you for trying to help ;-)

I've already checked that, but the calgo-API does not support a native key-up event. As a result, I have to depend on machine-specific key-up event listeners, which creates significant compatibility issues with MacOS. If you have working code for this issue, let me know.

The easiest would be to have a simple Property for the status of the modifier keys -available inside the robot/indicator. Or as I said, the modifier status should be submitted in the events that a user can create. Like pressing a button, similar to the mouse click event.

 

Best,
Carsten


@wolters