Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to AHK v2 #16

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions HotkeylessAHK.ahk
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
Menu, Tray, Icon, shell32.dll, 147
#singleinstance force

#Requires AutoHotkey v2.0
SendMode("Input")
SetWorkingDir(A_ScriptDir)
#SingleInstance force
#Include files\lib.ahk

; HotkeylessAHK by sebinside
Expand All @@ -21,11 +19,10 @@ RunClient()
Class CustomFunctions {

HelloWorld() {
MsgBox, Hello World
MsgBox "Hello, World!"
}

OpenExplorer() {
Run, explorer.exe
Run "explorer.exe"
}

}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Until now, you had only *two possible solutions*:
| Approach | Delay | Fast | Scalable |
| ----------------------- | :------- | :--: | :------: |
| Key combinations | ~ 10 ms | ✔ | 🞭 |
| Single AHK scripts | ~ 800 ms | 🞭 | ✔ |
| *Hotkeyless AutoHotkey* | ~ 100 ms | ✔ | ✔ |
| Single AHK scripts | ~ 73 ms | 🞭 | ✔ |
| *Hotkeyless AutoHotkey* | ~ 48 ms | ✔ | ✔ |

You can make your own *performance tests*. Just have a look at the `performance-tests`-folder!

Expand Down
9 changes: 4 additions & 5 deletions files/dist/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";
exports.__esModule = true;
var server_1 = require("./server");
var SERVER_PORT = 42800;
const HotkeylessAHKServer = require("./server");
const SERVER_PORT = 42800;
console.log("HotkeylessAHK by sebinside.");
var server = new server_1.HotkeylessAHKServer(SERVER_PORT);
server.setup();
const server = new HotkeylessAHKServer(SERVER_PORT);
server.setup();
170 changes: 104 additions & 66 deletions files/dist/server.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,107 @@
"use strict";
exports.__esModule = true;
exports.HotkeylessAHKServer = void 0;
var express = require("express");
var HotkeylessAHKServer = /** @class */ (function () {
function HotkeylessAHKServer(serverPort) {
var _this = this;
this.serverPort = serverPort;
// Setup server
this.app = express();
this.router = express.Router();

const express = require("express");

class HotkeylessAHKServer {
constructor(serverPort) {
this.serverPort = serverPort;
this.app = express();
this.router = express.Router();
this.pendingResult = null;
this.list = "";
this.functionClassMap = {};
}

subscribe = (req, res) => {
this.pendingResult = res;
console.log("Received subscriber.");
};

send = (req, res) => {
if (this.pendingResult !== null) {
const fullCommand = req.originalUrl.substring(6);
const [functionName, ...params] = fullCommand.split("?");

if (functionName === "kill") {
const command = `kill${params.length > 0 ? "?" + params.join("?") : ""}`;
this.pendingResult.send(command);
this.pendingResult = null;
this.list = "";
/**
* Handles the subscriber aka. redirecting ahk script
*/
this.subscribe = function (req, res) {
_this.pendingResult = res;
console.log("Received subscriber.");
};
/**
* Handles the sender aka the caller e.g. a stream deck
*/
this.send = function (req, res) {
if (_this.pendingResult !== null) {
var command = req.params.command;
_this.pendingResult.send(command);
_this.pendingResult = null;
res.send("success");
console.log("Send command: ".concat(command));
}
else {
console.error("No subscribing process registered. Please call '/subscribe' first!");
res.send("failure");
}
};
this.register = function (req, res) {
var list = req.params.list;
// This is required due to the last comma added in the ahk code
_this.list = list.substring(0, list.length - 1);
res.send("success");
};
this.getList = function (req, res) {
res.send(_this.list);
};
/**
* Stops the node process
*/
this.kill = function (req, res) {
console.log("Shutting down server...");
process.exit(0);
};
res.send("success");
console.log(`Send command: ${command}`);
this.kill(req, res);
return;
}

const functionClass = this.findFunctionClass(functionName);

if (functionClass) {
const command = `${functionClass}.${functionName}${
params.length > 0 ? "?" + params.join("?") : ""
}`;
this.pendingResult.send(command);
this.pendingResult = null;
res.send("success");
console.log(`Send command: ${command}`);
} else {
console.error(`Function '${functionName}' not found in any class.`);
res.send("failure");
}
} else {
console.error(
"No subscribing process registered. Please call '/subscribe' first!"
);
res.send("failure");
}
};

register = (req, res) => {
const list = req.params.list;
this.list = list.replace(/,/g, "\n");
const listArray = this.list.split("\n");
for (let i = 0; i < listArray.length; i += 2) {
const fullFunctionName = listArray[i];
const [functionClass, functionName] = fullFunctionName.split(".");
if (functionName !== "__Init") {
this.functionClassMap[functionName] = functionClass;
}
}
res.send("success");
};

getList = (req, res) => {
const listObjects = [];
for (const functionName in this.functionClassMap) {
if (
functionName !== "undefined"
) {
const note = "None";
listObjects.push({ command: functionName, note });
}
}
HotkeylessAHKServer.prototype.setup = function () {
console.log("Starting server...");
this.router.get("/subscribe", this.subscribe);
this.router.get("/send/:command", this.send);
this.router.get("/kill", this.kill);
this.router.get("/register/:list", this.register);
this.router.get("/list", this.getList);
// Start server
this.app.use('/', this.router);
this.app.listen(this.serverPort);
console.log("Server running on port ".concat(this.serverPort, "."));
console.log("Please use the '/subscribe' endpoint first!");
};
return HotkeylessAHKServer;
}());
exports.HotkeylessAHKServer = HotkeylessAHKServer;
res.json(listObjects);
};
kill = (req, res) => {
console.log("Shutting down server...");
process.exit(0);
};

findFunctionClass(functionName) {
return this.functionClassMap[functionName] || null;
}

setup() {
console.log("Starting server...");
this.router.get("/subscribe", this.subscribe);
this.router.get("/send/*", this.send);
this.router.get("/kill", this.kill);
this.router.get("/register/:list", this.register);
this.router.get("/list", this.getList);
this.app.use("/", this.router);
this.app.listen(this.serverPort, () => {
console.log(`Server running on port ${this.serverPort}.`);
console.log("Please use the '/subscribe' endpoint first!");
});
}
}

module.exports = HotkeylessAHKServer;
8 changes: 0 additions & 8 deletions files/index.ts

This file was deleted.

Loading