forked from arduino/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Mouse.moveAbs() as a new feature for absolute mouse positioning…
… as requested in issue arduino#1417. all parameters have the range of -32768 to 32767 and must be scaled to screen pixels some examples: x=0, y=0 is the middle of the screen x=-32768, y=-32768 is the top left corner x=32767, y=-32768 is the top right corner x=32767, y=32767 is the bottom right corner x=-32768, y=32767 is the bottom left corner
- Loading branch information
1 parent
674ab3b
commit 7b77d1e
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7b77d1e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No matter what permutation I use using the native map method, can't quite get this to work.
7b77d1e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using the following sketch for testing a year ago (I don't have an Arduino Leonardo right now to test it):
include "Platform.h"
// all of the screen_res constants must be !=0 to avoid division by zero
const int16_t screen_res_x = 1920; // must match the screen x resolution
const int16_t screen_res_y = 1280; // must match the screen y resolution
const int16_t screen_res_wheel = 1000; // is scaled from -1000 to 1000
// when you use it on a Mac, set border to 15%
if 1
// for Windows use a border of 0%
const int32_t borderPercent = 0L;
else
// for Max OSX use a border of 15%
// this is for solving the Max OSX border issue
const int32_t borderPercent = 15L;
endif
const int32_t minVal = -32768L; // must match the value of Logical Minimum in the mouse absolute descriptor in HID.cpp
const int32_t maxVal = 32767L; // must match the value of Logical Maximum in the mouse absolute descriptor in HID.cpp
const int32_t borderVal = ((maxVal - minVal + 1) * borderPercent / 200L);
uint32_t g_prevTime;
void setup()
{
Serial.begin(9600);
// initialize control over the mouse:
Mouse.begin();
g_prevTime = millis();
delay(10000);
}
void loop()
{
u32 m = millis();
u32 tDiff = m - g_prevTime;
if(tDiff >= 10) // one step each 10 ms
{
g_prevTime = m;
}
}
// translate screen coordinates to absolute mouse coordinates and move the mouse to that position
void moveMouseAbsScreen(int16_t x_screen, int16_t y_screen, int16_t wheel_screen)
{
int16_t x = map(x_screen, 0, screen_res_x - 1, minVal + borderVal, maxVal - borderVal);
int16_t y = map(y_screen, 0, screen_res_y - 1, minVal + borderVal, maxVal - borderVal);
int16_t wheel = map(wheel_screen, -screen_res_wheel, screen_res_wheel, minVal, maxVal);
Mouse.moveAbs(x, y, wheel);
}