add simple mouse controls
This commit is contained in:
+55
-7
@@ -91,6 +91,7 @@ div.menu a:hover {
|
|||||||
var keys = [];
|
var keys = [];
|
||||||
var fetchqueue = [];
|
var fetchqueue = [];
|
||||||
var curLed = 0;
|
var curLed = 0;
|
||||||
|
var sendKeyInterval = null;
|
||||||
const indicator_list = [
|
const indicator_list = [
|
||||||
{id: "num", label: "NumLock"},
|
{id: "num", label: "NumLock"},
|
||||||
{id: "caps", label: "CapsLock"},
|
{id: "caps", label: "CapsLock"},
|
||||||
@@ -102,7 +103,7 @@ const macro_list = [
|
|||||||
{id: "close", label: "ALT+F4", keys: ["AltLeft", "F4"]},
|
{id: "close", label: "ALT+F4", keys: ["AltLeft", "F4"]},
|
||||||
{id: "cycle", label: "ALT+Tab", keys: ["AltLeft", "Tab"]}
|
{id: "cycle", label: "ALT+Tab", keys: ["AltLeft", "Tab"]}
|
||||||
];
|
];
|
||||||
const key_list = [
|
const keyboard_list = [
|
||||||
[
|
[
|
||||||
{id: "Escape", label: "ESC", width: 2},
|
{id: "Escape", label: "ESC", width: 2},
|
||||||
{id: "F1", label: "F1"},
|
{id: "F1", label: "F1"},
|
||||||
@@ -223,6 +224,30 @@ const key_list = [
|
|||||||
{id: "NumpadDecimal", label: "Del<br>."}
|
{id: "NumpadDecimal", label: "Del<br>."}
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
const mouse_list = [
|
||||||
|
[
|
||||||
|
{id: "", label: ""},
|
||||||
|
{id: "MouseUp", label: "<br>⇑", repeat: 1},
|
||||||
|
{id: "", label: ""}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{id: "MouseLeft", label: "<br>⇐", repeat: 1},
|
||||||
|
{id: "", label: ""},
|
||||||
|
{id: "MouseRight", label: "<br>⇒", repeat: 1}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{id: "", label: ""},
|
||||||
|
{id: "MouseDown", label: "<br>⇓", repeat: 1},
|
||||||
|
{id: "", label: ""}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{id: "", label: "", width: 3}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{id: "MouseClickLeftt", label: "Left Click", width: 1.5, height: 0.75},
|
||||||
|
{id: "MouseClickRight", label: "Right Click", width: 1.5, height: 0.75}
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
window.setInterval("refreshIndicators();",2000);
|
window.setInterval("refreshIndicators();",2000);
|
||||||
|
|
||||||
@@ -231,7 +256,8 @@ window.addEventListener("keyup", onKeyUp, true);
|
|||||||
|
|
||||||
window.onload = (event) => {
|
window.onload = (event) => {
|
||||||
createMacros("macros");
|
createMacros("macros");
|
||||||
createKeys("keyboard");
|
createKeys("keyboard", keyboard_list);
|
||||||
|
createKeys("mouse", mouse_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onKeyDown(event) {
|
function onKeyDown(event) {
|
||||||
@@ -245,12 +271,15 @@ function onKeyDown(event) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
function pressKey(code) {
|
function pressKey(code, repeat=false) {
|
||||||
if (keys.includes(code)) { return; }
|
if (keys.includes(code)) { return; }
|
||||||
|
|
||||||
keys.push(code);
|
keys.push(code);
|
||||||
|
|
||||||
sendKeys(keys);
|
sendKeys(keys);
|
||||||
|
if ( sendKeyInterval == null && repeat) {
|
||||||
|
sendKeyInterval = setInterval( function() { sendKeys(keys); }, 200 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onKeyUp(event) {
|
function onKeyUp(event) {
|
||||||
@@ -264,19 +293,24 @@ function onKeyUp(event) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
function releaseKey(code) {
|
function releaseKey(code, repeat=false) {
|
||||||
if (keys.includes(code)) {
|
if (keys.includes(code)) {
|
||||||
keys.splice(keys.indexOf(code),1);
|
keys.splice(keys.indexOf(code),1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendKeys(keys);
|
sendKeys(keys);
|
||||||
|
|
||||||
|
if (sendKeyInterval != null && repeat) {
|
||||||
|
clearInterval(sendKeyInterval);
|
||||||
|
sendKeyInterval = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendKeys(curKeys) {
|
function sendKeys(curKeys) {
|
||||||
const url="sendkeys.cgi?keys=".concat(curKeys);
|
const url="sendkeys.cgi?keys=".concat(curKeys);
|
||||||
fetchqueue.push(url);
|
fetchqueue.push(url);
|
||||||
console.log(fetchqueue);
|
//console.log(fetchqueue);
|
||||||
document.getElementById("downKeys")
|
document.getElementById("downKeys")
|
||||||
.innerHTML = curKeys;
|
.innerHTML = curKeys;
|
||||||
prev_keys = document.getElementsByClassName("pressed");
|
prev_keys = document.getElementsByClassName("pressed");
|
||||||
@@ -314,8 +348,8 @@ function refreshIndicators() {
|
|||||||
indicatorFrame.contentWindow.location.reload(true);
|
indicatorFrame.contentWindow.location.reload(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createKeys(keyboard_id) {
|
function createKeys(div_id, key_list) {
|
||||||
let keyboardDiv = document.getElementById(keyboard_id);
|
let keyboardDiv = document.getElementById(div_id);
|
||||||
for (let row of key_list) {
|
for (let row of key_list) {
|
||||||
let newRow = document.createElement("div");
|
let newRow = document.createElement("div");
|
||||||
keyboardDiv.appendChild(newRow);
|
keyboardDiv.appendChild(newRow);
|
||||||
@@ -325,6 +359,16 @@ function createKeys(keyboard_id) {
|
|||||||
newDiv.id = key.id;
|
newDiv.id = key.id;
|
||||||
newDiv.innerHTML = key.label;
|
newDiv.innerHTML = key.label;
|
||||||
newDiv.className = "key";
|
newDiv.className = "key";
|
||||||
|
if (key.repeat) {
|
||||||
|
newDiv.addEventListener("touchstart", function (event) {
|
||||||
|
event.preventDefault(); pressKey(key.id, true); });
|
||||||
|
newDiv.addEventListener("touchend", function (event) {
|
||||||
|
event.preventDefault(); releaseKey(key.id, true); });
|
||||||
|
newDiv.addEventListener("mousedown", function () {
|
||||||
|
pressKey(key.id, true); });
|
||||||
|
newDiv.addEventListener("mouseup", function () {
|
||||||
|
releaseKey(key.id, true); });
|
||||||
|
} else {
|
||||||
newDiv.addEventListener("touchstart", function (event) {
|
newDiv.addEventListener("touchstart", function (event) {
|
||||||
event.preventDefault(); pressKey(key.id); });
|
event.preventDefault(); pressKey(key.id); });
|
||||||
newDiv.addEventListener("touchend", function (event) {
|
newDiv.addEventListener("touchend", function (event) {
|
||||||
@@ -333,6 +377,7 @@ function createKeys(keyboard_id) {
|
|||||||
pressKey(key.id); });
|
pressKey(key.id); });
|
||||||
newDiv.addEventListener("mouseup", function () {
|
newDiv.addEventListener("mouseup", function () {
|
||||||
releaseKey(key.id); });
|
releaseKey(key.id); });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
newDiv.className = "key blank";
|
newDiv.className = "key blank";
|
||||||
}
|
}
|
||||||
@@ -372,7 +417,10 @@ function createMacros(macro_id) {
|
|||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div id="keyboard"></div>
|
<div id="keyboard"></div>
|
||||||
|
<div>
|
||||||
<div id="indicators"></div>
|
<div id="indicators"></div>
|
||||||
|
<div id="mouse"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="macros"></div>
|
<div id="macros"></div>
|
||||||
|
|||||||
+931
-791
File diff suppressed because it is too large
Load Diff
+28
-4
@@ -13,7 +13,9 @@ void parse_key_list(char * keys) {
|
|||||||
uint8_t keypos = 2; // bytes 2-7 are used for normal keys
|
uint8_t keypos = 2; // bytes 2-7 are used for normal keys
|
||||||
uint8_t code = 0x00;
|
uint8_t code = 0x00;
|
||||||
static unsigned char boot_report[8];
|
static unsigned char boot_report[8];
|
||||||
|
static unsigned char mouse_report[3];
|
||||||
memset(boot_report, 0x00, 8);
|
memset(boot_report, 0x00, 8);
|
||||||
|
memset(mouse_report, 0x00, 3);
|
||||||
|
|
||||||
// Javascript sends the list as comma delimited, so split into individual
|
// Javascript sends the list as comma delimited, so split into individual
|
||||||
// keys by splitting at commas
|
// keys by splitting at commas
|
||||||
@@ -27,20 +29,43 @@ void parse_key_list(char * keys) {
|
|||||||
keypos++;
|
keypos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if a scan code was not returned, it might be a modifier
|
// if a scan code was not returned, it might be a modifier or mouse
|
||||||
|
if (code == 0x00) {
|
||||||
// search for the correct modifier bit and add it to byte 0 of the
|
// search for the correct modifier bit and add it to byte 0 of the
|
||||||
// USB boot keyboard report
|
// USB boot keyboard report
|
||||||
if (code == 0x00) {
|
|
||||||
code = parse_mod(token);
|
code = parse_mod(token);
|
||||||
if (code) {
|
if (code) {
|
||||||
boot_report[0] = boot_report[0] | code;
|
boot_report[0] = boot_report[0] | code;
|
||||||
|
} else if ( strncmp(&token[0],"Mouse", 5) == 0 ){
|
||||||
|
if ( strncmp(&token[5], "Left", 4) == 0 ) {
|
||||||
|
mouse_report[1] = -1*MOUSE_SPEED;
|
||||||
|
} else if ( strncmp(&token[5], "Right", 5) == 0 ) {
|
||||||
|
mouse_report[1] = 1*MOUSE_SPEED;
|
||||||
|
} else if ( strncmp(&token[5], "Up", 2) == 0 ) {
|
||||||
|
mouse_report[2] = -1*MOUSE_SPEED;
|
||||||
|
} else if ( strncmp(&token[5], "Down", 4) == 0 ) {
|
||||||
|
mouse_report[2] = 1*MOUSE_SPEED;
|
||||||
|
} else if ( strncmp(&token[5], "ClickLeft", 9) == 0 ) {
|
||||||
|
mouse_report[0] = mouse_report[0] | 1;
|
||||||
|
} else if ( strncmp(&token[5], "ClickRight", 10) == 0) {
|
||||||
|
mouse_report[0] = mouse_report[0] | 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
token = strtok(NULL, ",");
|
token = strtok(NULL, ",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// print resulting HID boot mouse report to CDC for debugging
|
||||||
|
printf("Mouse report: ");
|
||||||
|
for(int i=0; i<3; i++){
|
||||||
|
printf("%02X ",mouse_report[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
tud_hid_report(REPORT_ID_MOUSE, mouse_report, 3);
|
||||||
|
|
||||||
// print resulting HID boot keyboard report to CDC for debugging
|
// print resulting HID boot keyboard report to CDC for debugging
|
||||||
printf("HID report: ");
|
printf("Keyboard report: ");
|
||||||
for(int i=0; i<8; i++){
|
for(int i=0; i<8; i++){
|
||||||
printf("%02X ",boot_report[i]);
|
printf("%02X ",boot_report[i]);
|
||||||
}
|
}
|
||||||
@@ -75,4 +100,3 @@ uint8_t parse_mod(char * key) {
|
|||||||
}
|
}
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef PARSE_KEYS_H_
|
#ifndef PARSE_KEYS_H_
|
||||||
#define PRASE_KEYS_H_
|
#define PRASE_KEYS_H_
|
||||||
|
|
||||||
|
#define MOUSE_SPEED 10
|
||||||
|
|
||||||
static unsigned char boot_buf[8];
|
static unsigned char boot_buf[8];
|
||||||
|
|
||||||
void parse_key_list(char * keys);
|
void parse_key_list(char * keys);
|
||||||
|
|||||||
+2
-1
@@ -89,7 +89,8 @@ uint8_t const * tud_descriptor_device_cb(void)
|
|||||||
|
|
||||||
uint8_t const desc_hid_report[] =
|
uint8_t const desc_hid_report[] =
|
||||||
{
|
{
|
||||||
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD))
|
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD)),
|
||||||
|
TUD_HID_REPORT_DESC_MOUSE( HID_REPORT_ID(REPORT_ID_MOUSE))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ enum
|
|||||||
{
|
{
|
||||||
REPORT_ID_KEYBOARD = 1,
|
REPORT_ID_KEYBOARD = 1,
|
||||||
REPORT_ID_CONSUMER_CONTROL,
|
REPORT_ID_CONSUMER_CONTROL,
|
||||||
|
REPORT_ID_MOUSE,
|
||||||
REPORT_ID_COUNT
|
REPORT_ID_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user