說明
在連接的計算機上移動光標。屏幕上的運動總是相對於光標的當前位置。在使用 Mouse.move()
之前,您必須調用 Mouse.begin()
用法
Mouse.move(xVal, yVal, wheel)
參數
xVal
:沿 x 軸移動的量。允許的數據類型:signed char
.
yVal
: 沿 y 軸移動的量。允許的數據類型:signed char
.
wheel
: 移動滾輪的量。允許的數據類型:signed char
.
返回
無
示例代碼
#include <Mouse.h>
const int xAxis = A1; //analog sensor for X axis
const int yAxis = A2; // analog sensor for Y axis
int range = 12; // output range of X or Y movement
int responseDelay = 2; // response delay of the mouse, in ms
int threshold = range / 4; // resting threshold
int center = range / 2; // resting position value
int minima[] = {1023, 1023}; // actual analogRead minima for {x, y}
int maxima[] = {0, 0}; // actual analogRead maxima for {x, y}
int axis[] = {xAxis, yAxis}; // pin numbers for {x, y}
int mouseReading[2]; // final mouse readings for {x, y}
void setup() {
Mouse.begin();
}
void loop() {
// read and scale the two axes:
int xReading = readAxis(0);
int yReading = readAxis(1);
// move the mouse:
Mouse.move(xReading, yReading, 0);
delay(responseDelay);
}
/*
reads an axis (0 or 1 for x or y) and scales the
analog input range to a range from 0 to <range>
*/
int readAxis(int axisNumber) {
int distance = 0; // distance from center of the output range
// read the analog input:
int reading = analogRead(axis[axisNumber]);
// of the current reading exceeds the max or min for this axis,
// reset the max or min:
if (reading < minima[axisNumber]) {
minima[axisNumber] = reading;
}
if (reading > maxima[axisNumber]) {
maxima[axisNumber] = reading;
}
// map the reading from the analog input range to the output range:
reading = map(reading, minima[axisNumber], maxima[axisNumber], 0, range);
// if the output reading is outside from the
// rest position threshold, use it:
if (abs(reading - center) > threshold) {
distance = (reading - center);
}
// the Y axis needs to be inverted in order to
// map the movemment correctly:
if (axisNumber == 1) {
distance = -distance;
}
// return the distance for this axis:
return distance;
}
注意事項和警告
當您使用Mouse.move()
命令時,Arduino 會接管您的鼠標!在使用該命令之前,請確保您有控製權。切換鼠標控製狀態的按鈕是有效的。
相關用法
- Arduino Mouse.begin()用法及代碼示例
- Arduino Mouse.end()用法及代碼示例
- Arduino Mouse.click()用法及代碼示例
- Arduino Mouse.press()用法及代碼示例
- Arduino Mouse.isPressed()用法及代碼示例
- Arduino Mouse.release()用法及代碼示例
- Arduino Mouse - Mouse.click()用法及代碼示例
- Arduino Mouse - Mouse.press()用法及代碼示例
- Arduino Mouse - Mouse.isPressed()用法及代碼示例
- Arduino Mouse - Mouse.end()用法及代碼示例
- Arduino Mouse - Mouse.begin()用法及代碼示例
- Arduino Mouse - Mouse.move()用法及代碼示例
- Arduino Mouse - Mouse.release()用法及代碼示例
- Arduino MKRGSM - gprs.attachGPRS()用法及代碼示例
- Arduino MKRGSM - sms.read()用法及代碼示例
- Arduino MKRNB - getCurrentCarrier()用法及代碼示例
- Arduino MKRWAN - available()用法及代碼示例
- Arduino MKRNB - getIMEI()用法及代碼示例
- Arduino MKRWAN - version()用法及代碼示例
- Arduino MKRGSM - sms.print()用法及代碼示例
- Arduino MKRNB - endSMS()用法及代碼示例
- Arduino MKRGSM - client.connected()用法及代碼示例
- Arduino MKRGSM - voice.answerCall()用法及代碼示例
- Arduino MKRGSM - voice.hangCall()用法及代碼示例
- Arduino MKRGSM - sms.write()用法及代碼示例
注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 Mouse.move()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。