Login Page - Create Account

Support Board


Date/Time: Wed, 24 Apr 2024 07:31:18 +0000



Using Keyboard Shortcuts in ACSIL

View Count: 2227

[2019-03-02 21:31:27]
Yoda - Posts: 106
I've created a study where, thru menu events, I can do a number of things such as placing an entry and a stop loss on a chart. The study then calculates targets and again thru the menu, I can place an order at these levels. I also have the ability to clear these items.

I would now like to add the ability to assign shortcut keys to these activities so that I don't have to right click and choose an activity from the menu. For example:

CTRL SHIFT E - Places entry at price level where mouse is on the chart

CTRL SHIFT S - Places stop at price level where mouse is on the chart

CTRL SHIFT Z - Places OCO order based on set entry and stop and calculated targets.

CTRL SHIFT X - Clears the entry, stop and targets

Ideally, I would like to add the shortcut ability along side the MenuEventID lines...something like:

if (sc.MenuEventID == r_SetEntry || sc.ExecuteKeboardShortcut == EntryKeySequence)

...Where EntryKeySequence in this example would be defined as "CTRL SHIFT E"

Can someone please refer me to the documentation that discusses how this can be done.

If this is not possible, I ask that SC please consider adding this feature.

Thanks.
[2019-03-04 20:37:51]
Yoda - Posts: 106
Any assistance with this matter would be greatly appreciated.
[2019-03-05 02:15:57]
Sierra Chart Engineering - Posts: 104368
We needed time to do some documentation review and updates.

Refer to:
ACSIL Interface Members - Variables and Arrays: sc.KeyboardKeyEventCode
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2019-03-05 02:16:12
[2019-03-05 06:56:15]
Yoda - Posts: 106
Thanks for the reference. However I couldn't find any code examples of how to use keyboard events. So I've been testing different code, like the following

  sc.ReceiveKeyboardKeyEvents = 1;
  sc.ReceiveCharacterEvents = 1;
  sc.SupportKeyboardModifierStates = 1;
  
  int PressedKey = sc.KeyboardKeyEventCode;
  
  if (sc.MenuEventID == r_SetEntry || (sc.IsKeyPressed_Control && sc.IsKeyPressed_Shift && PressedKey == 69)) // E = 0x45 = 69 (Confirmed using sc.ReceiveKeyboardKeyEvents)
  {

I'm not sure what I'm doing wrong with above code. When <CTRL> <SHIFT> e is pressed the message log shows that the Control Shift and Windows virtual code 69 were pressed, but the code in the if statement does not run. The code does run in the if statement if I choose the r_SetEntry from the menu.

Any help would be appreciated.
[2019-03-05 18:31:11]
Sierra Chart Engineering - Posts: 104368
This is not something we are able to help with. The actual value set to sc.KeyboardKeyEventCode is set by the operating system. We have heard that value changes based on using the different modifier keys. You just have to figure this out.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-03-05 18:48:57]
Sierra Chart Engineering - Posts: 104368
Also check the value of:
ACSIL Interface Members - Variables and Arrays: sc.CharacterEventCode
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-03-08 03:55:02]
Yoda - Posts: 106
I was able to get the shortcut keys working with ASCIL and provide some comments below to help anyone reading this.

As an aside, I found the documentation a bit lacking on this topic and thought it might be helpful if SC included some of the following in the documentation.
I think it will also be immensely helpful if there were some coding examples. Accordingly, I have included a small script that I used when trying to figure out the shortcut keys. Please feel free to use parts or all of the script in the SC documentation.

Summary of findings (see script below for actual examples):

1. If a single key is pressed, i.e. the letter e, it appears that you can use sc.KeyboardKeyEventCode and a Windows Virtual Key Code number.
You can also use sc.CharacterEventCode and an ASCII number. You cannot use ASCII with sc.KeyboardKeyEventCode nor a Windows Virtual Key Code number with sc.CharacterEventCode.

2. It also appears that when trying to use a combination of keys (i.e. CTRL E) sc.KeyboardKeyEventCode and Windows Virtual Key Code number will NOT work.
For key combinations, one must use sc.CharacterEventCode and the ASCII value.

3.   Not all key combinations will work. Specifically, if the combination is already assigned i.e. CTRL S Which is assigned to File >> Save, it will not work.
  Trying to figure out which combinations are in use is a bit of a pain. Ideally, it would be nice if there was a way to print out the SC Keyboard Shortcuts with assigned values. Maybe SC will consider providing this option in a future release.
  In the meantime, the only way I could figure out to determine if a key combination is used, is to open up the Global Settings >> Customize Keyboard Shortcuts and select a key combination. Then see if something appears in the Key Currently Used By box.
  
4. I found that one has to be careful with different key combinations. For example: CTRL SHIFT E will correctly not trigger if you just use CTRL E. However, CTRL E and CTRL SHIFT E will BOTH trigger if CTRL SHFIT E is pressed. In other words, it appears that the SHIFT is ignored. See the code below for a specific example.

5. You can determine the ASCII and Window Virtual Key numbers by loading the SC provided custom study called Receive Keyboard Events Example.

Finally, here is the script. I hope this all helps and saves someone a lot of time.



/*=============================================================================
  *** Prepared for educational purposes only, see terms at end of code ***
  
  File: Keyboard-Test-v01a-20190307-2120.cpp
  Date last updated: 2019-03-07 2120

  NOTES:
  If a single key is pressed, it appears that one can use sc.KeyboardKeyEventCode
and the Windows Virtual Key Code number.

However, it appears that when trying to use a combination of keys, i.e. CTRL E
sc.KeyboardKeyEventCode and Windows Virtual Key Code number will NOT work.
For combinations, one must use sc.CharacterEventCode and the ASCII value.

See below for examples.
*/

#include "sierrachart.h"

SCDLLName("Keyboard Test v01a 03-07 2120 T4p DLL")
  
SCSFExport scsf_KeyboardTest01aT4p(SCStudyInterfaceRef sc)
{
  sc.GraphName = "Keyboard Test";

  sc.StudyDescription = "";

  sc.GraphRegion = 0;    

  sc.AutoLoop = 0;
    
  sc.ReceiveKeyboardKeyEvents = 1;

  sc.ReceiveCharacterEvents = 1;

  sc.SupportKeyboardModifierStates = 1;


  int PressedKey = sc.KeyboardKeyEventCode;
  int PressedChar = sc.CharacterEventCode;

  
  if ((PressedChar == 101)) // E = ASCII value of 101

  {
    SCString Message;

    Message.Format("sc.CharacterEventCode method - ASCII: E ( %d ) was pressed", PressedChar);        

    sc.AddMessageToLog(Message, 1);    
  }
  
  if ((PressedKey == 69)) // E = Windows Virtual Key value of 69

  {
    SCString Message;

    Message.Format("sc.KeyboardKeyEventCode metod - Windows Virtual Key: E ( %d ) was pressed", PressedKey);        

    sc.AddMessageToLog(Message,1);    
  }

  
  if ((sc.IsKeyPressed_Control && sc.IsKeyPressed_Shift && PressedChar == 5))

  {
    SCString Message;

    Message.Format("Control, Shift and E ( %d ) were pressed", PressedChar);        

    sc.AddMessageToLog(Message,1);    
  }

  // NOTE: The following will trigger even if you use another key in the combination.
  // i.e. When you press CTRL SHIFT E, the above if stmt triggers AND so does the one below.
  // Also note that you do not need to include sc.IsKeyPressed, only the ASCII code.
  
  if ((PressedChar == 5)) // CTRL E = ASCII value of 5

  {
    SCString Message;

    Message.Format("CTRL E ( %d ) were pressed", PressedChar);        

    sc.AddMessageToLog(Message,1);    
  }



// ****************** DISCLAIMER **********************************************
//
// This code is provided for educational purposes on an As Is, Where Is basis.
// No express or implied warranties are provided.
// There may be errors in this code, and it must not be used for live trading.
// Trading is very risky and you can lose more than you have invested.
// Past performance is not necessarily indicative of future results.
// By using any of this code, you acknowledge & agree to the above.
//
//=============================================================================
}


[2019-03-14 00:22:18]
Sierra Chart Engineering - Posts: 104368
We have done some documentation updates related to this.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account