Mouseclick events

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Mouseclick events

Postby arjfca » 11 Oct 2012

Hello

I don't see any mouseclick events in the wiki. Any one is using it?

Is Mouse click events only for MC.Net?

I want to test for,
- Grab price of a given bar
- Set a variable that will enable an indicator to be restart... 1' line of code being test the variable value


Martin :)

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Mouseclick events

Postby arjfca » 11 Oct 2012

Hello

Did try

Code: Select all

if MouseClickCtrlPressed then PlaySound ("C:\Users\Utilisateur\Documents\Bourse\Sound\Going Short.wav")
My understanding is that If left mouseclick and CTRL key is press, the condition should be true and the Playsound should be activated.

No event triggerd

Do we need to enable the event?
Can we cancel event lookout?

Martin

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Mouseclick events

Postby SP » 11 Oct 2012

You need [ProcessMouseEvents = True]; at the begin of the code.

Posted an example how to use here :
viewtopic.php?f=5&t=10067

and one here (sef file without source code)
viewtopic.php?f=5&t=9984

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Mouseclick events

Postby arjfca » 11 Oct 2012

You need [ProcessMouseEvents = True]; at the begin of the code.

Posted an example how to use here :
viewtopic.php?f=5&t=10067

and one here (sef file without source code)
viewtopic.php?f=5&t=9984
Thank you

I did test the code with

Code: Select all

[ProcessMouseEvents = True];

if MouseClickCtrlPressed then begin
[ProcessMouseEvents = false];

PlaySound ("C:\Users\Utilisateur\Documents\Bourse\Sound\Going Short.wav");

[ProcessMouseEvents = true];
end;
Problem is the mouseclickCtrl Pressed is recognized a multitudes of time. It read the file three times. In my code, I'm cancelling the event before executing the Playsound command but it seems that the events was already registered 3 time before going to the Playsound line.

Any idea how to avoid that?

Martin

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Mouseclick events

Postby SP » 11 Oct 2012

Use a intrabarpersist vars to play the sound only once. To recalculate your study take a look a ReCalcPersist and ReCalculate.

Code: Select all


[ProcessMouseEvents = True];
variables:
intrabarpersist Sound(false),ReCalcPersist recalc_once(True);

Once begin
Sound = True;
end;

if MouseClickCtrlPressed and LastBarOnChart_s and Sound = true then
begin
PlaySound ("C:\Users\Utilisateur\Documents\Bourse\Sound\Going Short.wav");
Sound = false;
If recalc_once Then
Begin
Print ("Recalculate study!");
recalc_once = False ;
ReCalculate;
End;
end;

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Mouseclick events

Postby arjfca » 11 Oct 2012

Use a intrabarpersist vars to play the sound only once. To recalculate your study take a look a ReCalcPersist and ReCalculate.

Code: Select all


[ProcessMouseEvents = True];
variables:
intrabarpersist Sound(false),ReCalcPersist recalc_once(True);

Once begin
Sound = True;
end;

if MouseClickCtrlPressed and LastBarOnChart_s and Sound = true then
begin
PlaySound ("C:\Users\Utilisateur\Documents\Bourse\Sound\Going Short.wav");
Sound = false;
If recalc_once Then
Begin
Print ("Recalculate study!");
recalc_once = False ;
ReCalculate;
End;
end;
Hello and thanks

What is the the usage of ReCalcPersist recalc_once(True); doing in it

I did look in the the Powerlanguage help, but I don't catch it

Martin :)

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Mouseclick events

Postby arjfca » 11 Oct 2012

Use a intrabarpersist vars to play the sound only once. To recalculate your study take a look a ReCalcPersist and ReCalculate.

Code: Select all


[ProcessMouseEvents = True];
variables:
intrabarpersist Sound(false),ReCalcPersist recalc_once(True);

Once begin
Sound = True;
end;

if MouseClickCtrlPressed and LastBarOnChart_s and Sound = true then
begin
PlaySound ("C:\Users\Utilisateur\Documents\Bourse\Sound\Going Short.wav");
Sound = false;
If recalc_once Then
Begin
Print ("Recalculate study!");
recalc_once = False ;
ReCalculate;
End;
end;
Negative, same problem. I did try to add the [ProcessMouseEvents = False]; before Playsound and re-enabled it after, but no change

It seem like the only way to cancel The Clickevent is to leftclick without clicking on the CTRL key. Otherwise, message is played for X amount of time

In electronic, we called that a re bounce on a switch. The PC is to fast and a lecture is done and record a multiple of time during the pressing down CTRL event.

Ways to compensate or resolve this problem is to add a capacitor + resistance to create an integrator.... but not applicable here. Or add a delay using code to allow only one lecture in a given time like 20 ms. Once click, no other reading of the keyboard should be allowed before the elapse of the delay. The delay should not be visible to the user and not slow down the code. This coding should be done at MC level. This would resolve the problem I think.

Martin

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Mouseclick events

Postby SP » 11 Oct 2012

I dont understand why you want to set [ProcessMouseEvents = False]; ?

If you want to reset the sound to be ready for one of the next click, add one more line

If MouseClickShiftPressed then Sound = true;

So if you press MouseClickCtrlPressed the sound appears one time, then use MouseClickShiftPressed to reset and if you press MouseClickCtrlPressed the sound plays one more time (and only one beep, not 3 ) and so on. Keep in mind to click on the chart, not on the subchart.

or for the next bar without MouseClick
if barstatus ( 1 ) = 2 then Sound = true;

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Mouseclick events

Postby arjfca » 11 Oct 2012

I dont understand why you want to set [ProcessMouseEvents = False]; ?

If you want to reset the sound to be ready for one of the next click, add one more line

If MouseClickShiftPressed then Sound = true;

So if you press MouseClickCtrlPressed the sound appears one time, then use MouseClickShiftPressed to reset and if you press MouseClickCtrlPressed the sound plays one more time (and only one beep, not 3 ) and so on. Keep in mind to click on the chart, not on the subchart.

or for the next bar without MouseClick
if barstatus ( 1 ) = 2 then Sound = true;
That was only for a test to see if the event was canceling while other procedure was taking place. I use this kind of canceling event in Excel VBA and in Micro- controler cpu chips at the start or a procedure to make sure that a new event won't disturb in anyway what I'm actually doing at the moment, but it look like MC does not response in the same manners.

Martin :)


Return to “MultiCharts”