Zelienople, PA, USA
Experience: Beginner
Platform: NinjaTrader
Trading: Futures
Posts: 1 since May 2015
Thanks Given: 1
Thanks Received: 0
|
I have been able to capture mouse movement and mouse clicks in Ninja Script. Portions of code (apprx 3,000 lines) are shown below. I can intercept the mouse clicks and read the keyboard state to decide how to process the click. The problem is that after intercepting the mouse click, I get the Ninja Trader "mouse action".
The question is: When I decide I want to capture a mouse click, how do I inhibit that mouse click from causing the default ninja trader actions? Alternatively, is there a way to disable the default mouse actions for some period of time, then re-enable them later (i.e. User clicks on a button. Disable all Ninja default mouse actions. Pick points on the chart and record them. Re-enable Ninja default mouse actions).
I am a beginner at this sort of thing, and would appreciate your help.
Thank you! Have a GREAT day!
SharkPub
Code for start up:
// --- mcdOnStartUp() --- Add to end of "OnStartUp()"
private void mcdOnStartUp()
{
if ( bDebug ) Print("mcdOnStartUp()");
bUpdated = false;
if ( (bInstalled = bIsBSModeActive()) == false ) {
// Print("mcdOnStartUp() - not active...");
return;
}
//add the mouse events
// Print("mcdOnStartUp()");
this.ChartControl.ChartPanel.MouseMove += new MouseEventHandler(mcdMouseEvent);
this.ChartControl.ChartPanel.MouseClick += new MouseEventHandler(mcdMouseEvent);
return;
}
Code for event handling:
private void mcdMouseEvent(object sender, MouseEventArgs e)
{
try
{
TriggerCustomEvent(new CustomEvent(mcdMouseTriggerEvent),e );
}
catch (Exception ex)
{
Print("Error1 " + ex.ToString());
}
}
private void mcdMouseTriggerEvent(object state)
{
int loc = 0;
int idx = -3;
int barclick = 0;
bool bDbg = false;
if ( !bUpdated )
return;
if ( curPt == null ) {
curPt = new chartPoint(this);
}
try
{
MouseEventArgs m = (MouseEventArgs)state;
loc = 1;
int bShift = 0, bAlt = 0, bCntrl = 0, bLeft = 0, bRight = 0;
bool bProcessed = false;
// Save points in case they changed
double tptShift0 = ptShift0;
double tptShift1 = ptShift1;
double tptAlt0 = ptAlt0;
double tptAlt1 = ptAlt1;
double tptCntrl0 = ptCntrl0;
double tptCntrl1 = ptCntrl1;
if ( m != null ) {
MouseButtons MBLeft = MouseButtons.Left;
MouseButtons MBRight = MouseButtons.Right;
bShift = (Control.ModifierKeys & Keys.Shift) != 0? 1:0;
bAlt = (Control.ModifierKeys & Keys.Alt) != 0? 2:0;
bCntrl = (Control.ModifierKeys & (Keys.ControlKey | Keys.Control)) != 0? 4:0;
if ( (bShift | bAlt | bCntrl) != 0 && (m.Button & (MBLeft | MBRight)) == (MBLeft | MBRight) ) {
// Both right and left button pressed, clear the oints
if ( bShift != 0 ) { ptShift0 = ptShift1 = 0; if ( bDbg ) Print(" pt Shift reset"); }
if ( bAlt != 0 ) { ptAlt0 = ptAlt1 = 0; if ( bDbg ) Print(" pt Alt reset"); }
if ( bCntrl != 0 ) { ptCntrl0 = ptCntrl1 = 0; if ( bDbg ) Print(" pt Cntrl reset"); }
} else if ( (bShift | bAlt | bCntrl) != 0 &&
(m.Button & (MBLeft | MBRight)) != 0 ) {
// set a point
curPt.setChartPosition(m.X,m.Y,1);
// Set the Y-position
double y = curPt.rYposTick;
if ( (m.Button & MBLeft) != 0 ) {
if ( bShift != 0 ) { ptShift0 = y; if ( bDbg ) Print(" pt Shift 0 set to: "+y.ToString("0.0000")); }
if ( bAlt != 0 ) { ptAlt0 = y; if ( bDbg ) Print(" pt Alt 0 set to: "+y.ToString("0.0000")); }
if ( bCntrl != 0 ) { ptCntrl0 = y; if ( bDbg ) Print(" pt Cntrl 0 set to: "+y.ToString("0.0000")); }
}
if ( (m.Button & MBRight) != 0 ) {
if ( bShift != 0 ) { ptShift1 = y; if ( bDbg ) Print(" pt Shift 1 set to: "+y.ToString("0.0000")); }
if ( bAlt != 0 ) { ptAlt1 = y; if ( bDbg ) Print(" pt Alt 1 set to: "+y.ToString("0.0000")); }
if ( bCntrl != 0 ) { ptCntrl1 = y; if ( bDbg ) Print(" pt Cntrl 1 set to: "+y.ToString("0.0000")); }
}
// Print("Shift="+(bShift==0?"up":"down")+" Alt="+(bAlt==0?"up":"down")+" Cntrl="+(bCntrl==0?"up":"down"));
// Print("Set point to "+y.ToString("0.0000"));
bProcessed = true;
// this.printChartControl(this);
}
// Check for one of the points changed position
if ( tptShift0 != ptShift0 || tptShift1 != ptShift1 ||
tptAlt0 != ptAlt0 || tptAlt1 != ptAlt1 ||
tptCntrl0 != ptCntrl0 || tptCntrl1 != ptCntrl1 ) {
// Force re-serialization of the data
barEntrySerialData.serializeClass( getInstrument(this), this );
}
....
}
}
catch (Exception ex)
{
Print("Error loc="+loc.ToString()+" computing projection bar: "+ex.ToString());
}
return;
}
|