Changed some HIDScripts

This commit is contained in:
mame82 2018-07-06 23:26:05 +00:00
parent 3a1ebdcb97
commit b7d0885fd6
2 changed files with 86 additions and 54 deletions

View File

@ -1,60 +1,92 @@
button(BTNONE);
// P4wnP1 HIDScript feature demo (Keyboard, JavaScript objects, Mouse and LED trigger logic)
//Log something to internal console
console.log("HID testscript");
typingSpeed(0,0); //type as fast as possible
layout("US"); //language layout
layout("US"); //set US layout
//Natural typing speed (100 ms between keys + additional jitter up to 200 ms)
typingSpeed(100,200);
type("Typing in natural speed");
layout("DE"); //Switching language layout, while script still running
//Fastest typing speed (no delays)
typingSpeed(0,0);
type("Typing fast, including unicode: üÜöÖäÄ");
//Do some relative mouse movement
for (var i = 0; i<10; i++) {
x = Math.random() * 256 - 128; //x, scaled between -128 and 127
y = Math.random() * 256 - 128; //y, scaled between -128 and 127
move(x,y);
delay(500); //wait a half a second
}
//Do some relative mouse movement, but divide it into 1 DPI substeps (pixel perfect mouse move, but slow)
for (var i = 0; i<10; i++) {
x = Math.random() * 256 - 128; //x, scaled between -128 and 127
y = Math.random() * 256 - 128; //y, scaled between -128 and 127
moveStepped(x,y);
delay(500); //wait a half a second
}
//Do some absolute Mouse positioning (not stepped, mouse moves immediately, thus delays are added)
moveTo(0.2,0.2);
delay(1000);
moveTo(0.8,0.2);
delay(1000);
moveTo(0.8,0.8);
delay(1000);
moveTo(0.2,0.8);
delay(1000);
//press button 1, move mouse stepped, release button 1
console.log("Moving mouse with button 1 pressed");
button(BT1);
moveStepped(20,0);
button(BTNONE);
//Start paint
waitLEDRepeat(NUM);
press("GUI R");
delay(500);
type("mspaint\n"); //no need to press ENTEr, encoded in '\n'
delay(1000);
//Maximize paint
press("GUI UP");
//Set canvas size to 1920x1080
press("CTRL E"); //open properties
delay(500);
type("1920");
press("TAB");
type("1080");
press("ENTER");
//Click button 2
console.log("Click button 2");
click(BT2);
//create JavasCript player object
var player = {
speed: 4.0/1920.0,
dir: 0.0,
pos: {"x": 0.5, "y":0.5},
border: {"lx": 0.2, "ly":0.2, "hx": 0.8, "hy": 0.8},
pressed: false,
step : function() {
v = this.getVec();
this.pos.x += v.x;
this.pos.y += v.y;
if (this.pos.x < this.border.lx ||
this.pos.x > this.border.hx ||
this.pos.y < this.border.ly ||
this.pos.y > this.border.hy)
return false;
this.moveMouseToPos();
return true;
}
getVec : function() {
x = Math.sin(this.dir) * this.speed;
y = Math.cos(this.dir) * this.speed;
return {"x": x, "y":y};
}
moveMouseToPos : function() {
moveTo(this.pos.x, this.pos.y)
}
toggleButton : function() {
if (this.pressed) button(BT1);
else button(BTNONE);
this.pressed = !this.pressed;
}
};
//Doubleclick button 1
console.log("Double click button 2");
doubleClick(BT1);
//draw border (delays only for visual fx)
delay(500);
moveTo(player.border.lx, player.border.ly);
button(BT1);
moveTo(player.border.hx, player.border.ly); delay(500);
moveTo(player.border.hx, player.border.hy); delay(500);
moveTo(player.border.lx, player.border.hy); delay(500);
moveTo(player.border.lx, player.border.ly);
button(BTNONE);
//release all buttons
button(BTNONE);
//game, exits when player position is outside border (absolute mouse positioning)
var turn = Math.PI / 4.0;
while (true) {
res = waitLED(ANY, 50) //wait 50ms for keyboard LED change
if (res.TIMEOUT) { //no LED change --> reposition mouse according to player.dir
if (!player.step()) { button(BTNONE); break; } //abort if player.pos outside player.border
}
if (res.CAPS) player.dir -= turn; //CAPSLOCK LED change --> turn player left
if (res.NUM) player.dir += turn; //NUMLOCK LED change --> turn player right
if (res.SCROLL) player.toggleButton(); //SCROLLLOCK LED change --> toggle mouse button1 on/off (draw)
}
//draw 100 random lines from center
moveTo(0.5,0.5);
button(BT1);
for (var i = 0; i<100; i++) {
x = Math.random(); //x, scaled between -128 and 127
y = Math.random(); //y, scaled between -128 and 127
moveTo(x,y);
moveTo(0.5,0.5);
delay(20); //wait a half a second
}
button(BTNONE);
//End paint (discard changes)
press("ALT F4"); press("TAB"); press("ENTER");