在方向改变时平滑线条,用java Robot模拟用户从模式输入
所以我正在创建一个模拟用户鼠标移动的应用程序 我有一个[步数,方向]在方向改变时平滑线条,用java Robot模拟用户从模式输入,java,math,input,robot,Java,Math,Input,Robot,所以我正在创建一个模拟用户鼠标移动的应用程序 我有一个[步数,方向] pattern.put(Weapon.NAME_TEST_DOWN2, new int[][]{ //sens: 1.0 steps:5,10ms delay {600, DOWN}, {100, RIGHT | DOWN}, {400, LEFT | DOWN}, {100, LEFT}, {200, N
pattern.put(Weapon.NAME_TEST_DOWN2, new int[][]{ //sens: 1.0 steps:5,10ms delay
{600, DOWN},
{100, RIGHT | DOWN},
{400, LEFT | DOWN},
{100, LEFT},
{200, NONE},
{600, RIGHT},
{400, NONE},
{400, LEFT}
});
很明显,摩苏埃的动作很快,需要进行平滑处理,使其看起来像人类,如图所示:
整个鼠标移动的功能是:
private final int stepAmount = 1;
@SuppressWarnings("FieldMayBeFinal")
private int delay = (int) (2 * CsgoRr.getModel().getAppPrefs().getIngameSensitivity()); // increments of 1 1.5 2 2.5 etc
@SuppressWarnings("CallToPrintStackTrace")
public void reduceRecoil() {
@SuppressWarnings("UnusedAssignment")
int directionFlag = 0;
int previousDirectionFlag;
int nextDirectionFlag = RecoilPatternInfo.NONE;
for (int row = 0; row < recoilPattern.length; row++) {
if (weapon.isTriggerPulled()) {
int duration = recoilPattern[row][0];
directionFlag = recoilPattern[row][1];
previousDirectionFlag = (row != 0) ? recoilPattern[row - 1][1] : RecoilPatternInfo.NONE;
try {
nextDirectionFlag = recoilPattern[row + 1][1];
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
switch (directionFlag) {
case (RecoilPatternInfo.DOWN): {
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x,
MouseInfo.getPointerInfo().getLocation().y + stepAmount);
} else {
return;
}
this.delay(delay);
}
break;
}
case (RecoilPatternInfo.DOWN | RecoilPatternInfo.LEFT): {
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x - stepAmount,
MouseInfo.getPointerInfo().getLocation().y + stepAmount);
} else {
return;
}
this.delay(delay);
}
break;
}
case (RecoilPatternInfo.DOWN | RecoilPatternInfo.RIGHT): {
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x + stepAmount,
MouseInfo.getPointerInfo().getLocation().y + stepAmount);
} else {
return;
}
this.delay(delay);
}
break;
}
case (RecoilPatternInfo.LEFT): {
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x - stepAmount,
MouseInfo.getPointerInfo().getLocation().y);
} else {
return;
}
this.delay(delay);
}
break;
}
case (RecoilPatternInfo.RIGHT): {
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x + stepAmount,
MouseInfo.getPointerInfo().getLocation().y);
} else {
return;
}
this.delay(delay);
}
break;
}
case (RecoilPatternInfo.UP): {
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x,
MouseInfo.getPointerInfo().getLocation().y - stepAmount);
} else {
return;
}
this.delay(delay);
}
break;
}
case (RecoilPatternInfo.UP | RecoilPatternInfo.LEFT): {
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x - stepAmount,
MouseInfo.getPointerInfo().getLocation().y - stepAmount);
} else {
return;
}
this.delay(delay);
}
break;
}
case (RecoilPatternInfo.UP | RecoilPatternInfo.RIGHT): {
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x + stepAmount,
MouseInfo.getPointerInfo().getLocation().y - stepAmount);
} else {
return;
}
this.delay(delay);
}
break;
}
default: {//RecoilPatternInfo.NONE
while ((duration -= delay) > 0) {
if (weapon.isTriggerPulled()) {
mouseMove(MouseInfo.getPointerInfo().getLocation().x,
MouseInfo.getPointerInfo().getLocation().y);
} else {
return;
}
this.delay(delay);
}
}
}
}
}
}
private final int stepaum=1;
@SuppressWarnings(“FieldMaybeffinal”)
private int delay=(int)(2*CsgoRr.getModel().getAppPrefs().getIngameSensitivity());//增量为1 1.5 2.5等
@SuppressWarnings(“CallToPrintStackTrace”)
公共void reduceRecoil(){
@抑制警告(“未指定”)
int directionFlag=0;
int-previousDirectionFlag;
int-nextDirectionFlag=RecoilPatternInfo.NONE;
for(int row=0;row0){
if(武器.IsTriggerPull()){
mouseMove(MouseInfo.getPointerInfo().getLocation().x,
MouseInfo.getPointerInfo().getLocation().y+stepAmount);
}否则{
返回;
}
这个.耽搁(耽搁),;
}
打破
}
案例(RecoilPatternInfo.DOWN | RecoilPatternInfo.LEFT):{
而((持续时间-=延迟)>0){
if(武器.IsTriggerPull()){
mouseMove(MouseInfo.getPointerInfo().getLocation().x-stepAmount,
MouseInfo.getPointerInfo().getLocation().y+stepAmount);
}否则{
返回;
}
这个.耽搁(耽搁),;
}
打破
}
案例(RecoilPatternInfo.DOWN | RecoilPatternInfo.RIGHT):{
而((持续时间-=延迟)>0){
if(武器.IsTriggerPull()){
mouseMove(MouseInfo.getPointerInfo().getLocation().x+stepAmount,
MouseInfo.getPointerInfo().getLocation().y+stepAmount);
}否则{
返回;
}
这个.耽搁(耽搁),;
}
打破
}
案例(反冲模式信息左):{
而((持续时间-=延迟)>0){
if(武器.IsTriggerPull()){
mouseMove(MouseInfo.getPointerInfo().getLocation().x-stepAmount,
MouseInfo.getPointerInfo().getLocation().y);
}否则{
返回;
}
这个.耽搁(耽搁),;
}
打破
}
案例(RecoilPatternInfo.RIGHT):{
而((持续时间-=延迟)>0){
if(武器.IsTriggerPull()){
mouseMove(MouseInfo.getPointerInfo().getLocation().x+stepAmount,
MouseInfo.getPointerInfo().getLocation().y);
}否则{
返回;
}
这个.耽搁(耽搁),;
}
打破
}
案例(RecoilPatternInfo.UP):{
而((持续时间-=延迟)>0){
if(武器.IsTriggerPull()){
mouseMove(MouseInfo.getPointerInfo().getLocation().x,
MouseInfo.getPointerInfo().getLocation().y-步进量);
}否则{
返回;
}
这个.耽搁(耽搁),;
}
打破
}
案例(RecoilPatternInfo.UP | RecoilPatternInfo.LEFT):{
而((持续时间-=延迟)>0){
if(武器.IsTriggerPull()){
mouseMove(MouseInfo.getPointerInfo().getLocation().x-stepAmount,
MouseInfo.getPointerInfo().getLocation().y-步进量);
}否则{
返回;
}
这个.耽搁(耽搁),;
}
打破
}
案例(RecoilPatternInfo.UP | RecoilPatternInfo.RIGHT):{
而((持续时间-=延迟)>0){
if(武器.IsTriggerPull()){
mouseMove(MouseInfo.getPointerInfo().getLocation().x+stepAmount,