Login Page - Create Account

Support Board


Date/Time: Sun, 06 Jul 2025 05:31:24 +0000



Post From: KeyboardKeyEventCode + PointerEventType

[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);
      }
    }
  }
  
}