Login Page - Create Account

Support Board


Date/Time: Sat, 05 Jul 2025 20:52:38 +0000



[Programming Help] - KeyboardKeyEventCode + PointerEventType

View Count: 1350

[2019-03-14 15:33:22]
User462086 - Posts: 196
I'm starting to play with ASCIL. My idea is to write the word "SUCCESS" to the message log when the left mouse button is clicked while the SHIFT + S buttons are being held down simultaneously. Each event is being caught individually, and both the keyboard events are caught when both keys are pressed and held down. However, the combination of the 3 events doesn't print "SUCCESS" as expected. Does anyone know how to get this working? Many thanks!!


// The top of every source code file must include this line
#include "sierrachart.h"

// For reference, refer to this page:
// Advanced Custom Study Interface and Language (ACSIL)

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("My First Custom DLL")

//This is the basic framework of a study function. Change the name 'TemplateFunction' to what you require.
SCSFExport scsf_MyFirstCustomDLL(SCStudyInterfaceRef sc)
{
  SCString MessageText;

  // Set configuration variables
  if (sc.SetDefaults)
  {
    sc.GraphName = "My First Custom DLL";

    sc.StudyDescription = "";

    sc.GraphRegion = 0;    

    // We have expressly set Autolooping to off because we are not filling
    // in any of the Subgraph[].Data[] arrays. Since Autolooping will
    // cause this function to be called for every bar in the chart it
    // would be inefficient to use Autolooping.
    sc.AutoLoop = 0;

    sc.ReceiveKeyboardKeyEvents = 1;
    sc.SupportKeyboardModifierStates = 1;
    sc.ReceivePointerEvents = ACS_RECEIVE_POINTER_EVENTS_ALWAYS;

    return;
  }

  // wait for an event
  
  bool shiftPressed   = sc.IsKeyPressed_Shift;
  bool sPressed    = sc.KeyboardKeyEventCode == 83;
  bool lClick    = sc.PointerEventType == SC_POINTER_BUTTON_DOWN;
  
  if( shiftPressed ){
    sc.AddMessageToLog("Shift Pressed", 0);
  }
  
  if( sPressed ){
    sc.AddMessageToLog("S Pressed", 0);
  }
  
  if( lClick ){
    sc.AddMessageToLog("Left Click", 0);
  }
  
  if( shiftPressed && sPressed ){  
    if( lClick ){
      sc.AddMessageToLog("SUCCESS", 0);
    }
  }

}




[2019-03-15 06:24:46]
Sierra Chart Engineering - Posts: 104368
You will probably want to use character events instead:
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-15 11:02:19]
User462086 - Posts: 196
I tried using character events as suggested, but without success. It should be said that I have absolutely zero C++ programming experience. Luckily, I was able to port some working C-based code that I had written for another platform. Here it is for anyone that might need it. You might need to uncomment the "#include <windows.h>" line if it's not compiling.


// The top of every source code file must include this line
//#include <windows.h>
#include "sierrachart.h"

// For reference, refer to this page:
// Advanced Custom Study Interface and Language (ACSIL)

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("AsyncKeyStateTest")

//This is the basic framework of a study function. Change the name 'TemplateFunction' to what you require.
SCSFExport scsf_AsyncKeyStateTest(SCStudyInterfaceRef sc)
{
  SCString MessageText;

  // Set configuration variables
  if (sc.SetDefaults)
  {
    sc.GraphName = "Async Key State Test";

    sc.StudyDescription = "";

    sc.GraphRegion = 0;    

    // We have expressly set Autolooping to off because we are not filling
    // in any of the Subgraph[].Data[] arrays. Since Autolooping will
    // cause this function to be called for every bar in the chart it
    // would be inefficient to use Autolooping.
    sc.AutoLoop = 0;

    return;
  }
  
  // wait for an event
  
  SHORT shiftPressed  = GetAsyncKeyState(VK_LSHIFT);
  SHORT sKeyPressed  = GetAsyncKeyState(83);  // "S" key
  SHORT lClick    = GetAsyncKeyState(VK_LBUTTON);
  
  if( 0 != shiftPressed ){
    
    if( 0 != sKeyPressed ){
      
      if( 0 != lClick ){
        sc.AddMessageToLog("SUCCESS", 0);
      }
    }
  }
  
}



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

Login

Login Page - Create Account