OBJ_EDIT focus - page 3

 
Petr Nosek:

Thank you for your reply ;-)

For a better user experience, I would suggest you to record the mouse position, and move it back once your stuff is done. I don't like to see my mouse moving by itself using any software.

 
Alain Verleyen:

For a better user experience, I would suggest you to record the mouse position, and move it back once your stuff is done. I don't like to see my mouse moving by itself using any software.

Of course you are right. It is just draft and in my code I'll return the mouse back if a cat doesn't catch it in the meantime :D
 
Alain Verleyen:

For a better user experience, I would suggest you to record the mouse position, and move it back once your stuff is done. I don't like to see my mouse moving by itself using any software.

#import "user32.dll"
   void  mouse_event(int dwFlags,int dx,int dy,int dwData,int dwExtraInfo);
   bool  GetCursorPos(POINT &lpPoint);
   bool  SetCursorPos(int x,int y);
   bool  GetWindowRect(int hWnd,RECT &lpRect);
   int   GetSystemMetrics(int nIndex);
#import
void MouseClick(const int x, const int y)
  {
   Sleep(50);
   POINT currentPoint;
   GetCursorPos(currentPoint);
   POINT clickPoint=ConvertXY(x,y);
   mouse_event(0x8007,clickPoint.posX,clickPoint.posY,0,0);
   SetCursorPos(currentPoint.posX,currentPoint.posY);
   Sleep(50);
  }

Based on your comments, I've improved my code. I've imported GetCursorPos() and SetCursorPos() and used them in my function MouseClick() . Now it seems that the mouse hasn't moved.

 
Petr Nosek:

Based on your comments, I've improved my code. I've imported GetCursorPos() and SetCursorPos() and used them in my function MouseClick() . Now it seems that the mouse hasn't moved.

Nice job. However doesn't seems reliable on my side (but my touchpad is a bit capricious). Sometimes the EDIT object doesn't get the focus.

 
Alain Verleyen:

Nice job. However doesn't seems reliable on my side (but my touchpad is a bit capricious). Sometimes the EDIT object doesn't get the focus.

I think your touchpad is not guilty. Maybe it helps if you increase milliseconds in Sleep(50) for example to Sleep(100). I do not know exact procedure how to an object is placed on a chart. It seems to be first stored in a queue, and then (I do not know exactly when) will be inserted on the chart. And that delay creates a problem. Sometimes function MouseClick() causes "click" before creating object. Maybe I'm wrong. If you have an idea I'll be thankful for sharing.

 
Petr Nosek:

I think your touchpad is not guilty. Maybe it helps if you increase milliseconds in Sleep(50) for example to Sleep(100). I do not know exact procedure how to an object is placed on a chart. It seems to be first stored in a queue, and then (I do not know exactly when) will be inserted on the chart. And that delay creates a problem. Sometimes function MouseClick() causes "click" before creating object. Maybe I'm wrong. If you have an idea I'll be thankful for sharing.

Well from a script there is not much alternative. I increase the delay to maximum 200 ms, seems reasonable and give better results.

With EA/indicators you can work with events.

EDIT: nope even with 200 ms I just get the problem again.
Reason: