looking to simulate a mouse click

edited September 2019 in Kinect

im looking to click on the draw window when is open and click on a face but without using the mouse to do so, it be better if processing had a voice recognition library but since im yet to come across such sketch i like to simulate a mouse click with a given screen x&y coord'n

    import gab.opencv.*;
    import processing.video.*;
    import java.awt.*;

    Capture video;
    OpenCV opencv;

    void setup() {
      size(640, 480);

      video = new Capture(this, 640/2, 480/2, "360HD Hologen");
      opencv = new OpenCV(this, 640/2, 480/2);


    void draw() {

      image(video, 0, 0 );

      stroke(0, 255, 0);
      Rectangle[] faces = opencv.detect();

      for (int i = 0; i < faces.length; i++) {
        rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);



  • @GotToLoop thanks for your time, listen is there a link more specific to making a mouse left click simulation happen? this is all i need really,

  • import java.awt.Robot;
    import java.awt.InputEvent;
    Robot.mouseMove(faceX, faceY);
    Robot.mousePress(InputEvent.BUTTON1_MASK); // Left=Button1, right=Button2
  • JaiJai
    edited April 2016

    this is what i got and lol im lost, i know this is a whole diff code but im moving kinda fast as im finding new way to do what i need done so this code is better because even if there was no face i can just click on the screen it self and that would be just fine and easy to adapt i guess VS if im only looking for a face to click on then i be fucked if i came across multiple faces "then what ? " so i think for now i just need to get familiar with this simulators first

    import java.awt.AWTException;
    import java.awt.Robot;
    import java.awt.event.KeyEvent;
    Robot robot;
    void setup() {
      size(400, 400);
      //Let's get a Robot...
      try { 
        robot = new Robot();
      catch (AWTException e) {
    void draw() {
      void mousePress(int buttons) {
        String mousePress = "meet";// this string will come via serial from visual studios2013
        // when this string comes in i want the processing to simulate a left mouse key on 
        // the coordinates given in mouseMove()
      void mouseMove(int x, int y) {
        x = 200;
        y = 400;
        mousePress(int BUTTON1);// would like to simulate left mouse click 
        mouseRelease(int BUTTON1)//then release that button
          //then go back to the last function or next function

    this code though it is not compiling

  • Answer ✓

    You can't have functions defined inside others. Move mousePress and moveMove outside the draw function.

  • Answer ✓

    You java.awt.Robot object is called robot, but mousePress() doesn't have the object there. So its:

    The InputEvent.BUTTON1_MASK is just an integer. It tells mousePress which button to click.
    In order to use InputEvet, you need to include it also.
    import java.awt.event.InputEvent;

    Look at this function I made which minimizes a maximized window and returns the mouse to the center of the screen:

    void robotCompleteScan() { // last robotFunc() called.
      robot.mouseMove(MinButtonXY[0], MinButtonXY[1]); // X Y location of button.
        robot.mousePress(InputEvent.BUTTON1_MASK); delay(100); // Wait for OS.
      robot.mouseRelease(InputEvent.BUTTON1_MASK); delay(100); 
      robot.mouseMove(displayWidth/2, displayHeight/2);
  • JaiJai
    edited April 2016

    thanks! i got it now, now one last thing ....if i want to call this function in the middle of another function, how do i call this func and then after the move and click has been done close that func and still remain on the original function prior to calling the simulate func?

    i would like to call it via serial 'meaning assign a string so that i can initiate that simulate click' from visualStudio using serial port.

    i mean i know how to write the whole serial part what i mean is that i dont know the structure require to have face detection on and while is on i would call via serial the simulate click function .

    void SimClk() {
      int x = 600;
      int y = 400;
      rbt.mouseMove(x, y);

    then after the SimClk() do its thing exit(); but not exit() the facedetect or any other function that was running prior to SimClk(), basically i dont want processing to ever end because he point is that i wont be in reach of the pc to click run again

  • @quark i mean i know how to write the whole serial part what i mean is that i dont know the structure require to have face detection on and while is on i would call via serial the simulate click function .

Sign In or Register to comment.