Help with mouse movement

Status
Not open for further replies.

C0keq

New member
I am trying to have my teensy emulate a mouse, but I am failing. I cannot get it to move the cursor. I have tried using the code from https://www.pjrc.com/teensy/td_mouse.html however, it still does not work. I am using a teensy 3.2 and I am trying to emulate a mouse on a mac. To find my cursor position I use command+shift+4 (also I have defined the variables openapp later in my code). I am trying to move the mouse to 452, 226 and later 457, 192. Any advice?
Code:
#include <Bounce.h>
int led = 13;
int ds = 500;
Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10); 

void setup() {
Mouse.screenSize(1920, 1080, true);  
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(led, OUTPUT);

  button4.update();
  button5.update();

  
  delay(1000);
  openapp("System Preferences");
  delay(ds);
  openapp("Terminal");
  cmd(KEY_N);
  typeln("osascript -e 'tell application \"System Events\" to set bounds of window \"System Preferences\" of application \"System Preferences\" to {0, 0, 700, 700}'"); 
  cmd(KEY_TAB);
  cmd(KEY_F);
  typeln("Wi-Fi");
  k(KEY_ENTER);
  delay(ds);


  //moving to network name selection
   if (button4.fallingEdge()) {
    Mouse.moveTo(452, 226); //doesn't work       
  }
 
Can you trim this down to a small program without all that other stuff, and then post the complete program. By complete, I mean anyone can copy and paste it into Arduino and upload it to their board and touch a wire between GND and pins 4 or 5 to do the mouse movements.

The code you posted isn't complete. There's no loop(). Every indication from what little you've shows is it updates the buttons only 1 time right at the beginning (before enough time to actually press them), and then looks for a change only once after doing a bunch of stuff. Maybe you did more in loop, but nobody can tell because you didn't post a complete program. Please, trim this to just showing the mouse problem and post a complete program and anyone can actually copy into Arduino and run on a board.
 
I appreciate your response and I know the code above isn't complete. I'm only having a problem with the mouse part of it. I cut out the bottom half because it didn't involve the mouse function. I need the teensy to emulate a mouse not physically be one.

I'm confused about this ---> "Teensy3 supports positioning. First, use Mouse.screenSize(width, height) to configure Teensy for your screen. Then you can use Mouse.moveTo(x, y) to precisely position the mouse at any pixel on your screen.
Code:
#include <Bounce.h>

Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10);

void setup() {
  Mouse.screenSize(1920, 1080);  // configure screen size
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
}

void loop() {
  button4.update();
  button5.update();
  if (button4.fallingEdge()) {
    Mouse.moveTo(25, 100);       // point to pixel at 25, 100
  }
  if (button5.fallingEdge()) {
    Mouse.moveTo(1580, 14);      // point to pixel at 1580, 14
  }
}
For Macintosh computers, use Mouse.screenSize(width, height, true). This extra parameter tells Teensy to use an alternate algorithm for correct positioning on Apple's OS-X operating system."

I just don't understand this code from: https://www.pjrc.com/teensy/td_mouse.html
I need the teensy to emulate a mouse.
Thanks again.
 
Status
Not open for further replies.
Back
Top