Krombik / keysender

Node.js Desktop Automation for Windows.
MIT License
82 stars 9 forks source link

let keyboard sending combine keys to non-active window work like ctrl + v #20

Closed YMC-GitHub closed 4 months ago

YMC-GitHub commented 1 year ago

Thanks for sharing, contributing.Your work has helped me a lot.Sorry to disturb you in your busy schedule!It is an honor and look forward to receiving your help! env:

nodejs:16.14.2
pnpm: 6.34.0
keysender 2.0.0 (i  try to run with  2.0.4,2.3.0 versions)

code:

//
await obj.keyboard.sendKey(["alt", "y"]);// in some game;not work;
// to debug if sendKey,toggleKey works in other window
await obj.keyboard.sendKey(["ctrl", "f"]);  in vscode;not work;

await obj.keyboard.sendKey(["y"]);  in some game;work;
await obj.keyboard.sendKey(["f"]);  in vscode;work;

act: in some game window : it input y char to its input box!(the y key fired!) in vscode window: ( to debug if sendKey,toggleKey works in other window) it did not do nothing.

expect: in some game window : enter some state. in vscode window: open finding view

YMC-GitHub commented 1 year ago

why close:(it works) active window before sending ctr,alt key with hardware

code sample:

function activeWindow(handle: number, hardware: boolean = false) {
    const obj = hardware ? new Hardware(handle) : new Virtual(handle); // or Virtual
    let cango = !obj.workwindow.isOpen() || !obj.workwindow.isForeground()
    if (cango) {
        obj.workwindow.setForeground();
    }
}
async function sendKeys(handle: number, keys: any[], hardware: boolean = false) {
    //keys :KeyboardButton | KeyboardButton[]
    const obj = hardware ? new Hardware(handle) : new Virtual(handle); // or Virtual
    await obj.keyboard.sendKey(keys);

}

activeWindow(wi.handle, true) //open window(active window) with hardware (with Virtual? you can try).
await sendKeys(wi.handle, ["alt", "y"], true)//works with hardware 
await sendKeys(wi.handle, ["alt", "y"], false)//not works with Virtual
YMC-GitHub commented 4 months ago

hey man, i would like to send modifier + key in virtual mode like ctrl + f.

it could work with this code in virtual mode ?

PostMessageA(hWnd, isKeyDown ? WM_KEYDOWN : WM_KEYUP, key, 0 | (key << 16) | (0 << 24) | (0 << 29) | ((UINT)!isKeyDown << 30) | ((UINT)!isKeyDown << 31))

and i am rewrite(refator) some features like this repo in rust. could you give me some help?

i am reading docs like :

but i am newer in cpp.

YMC-GitHub commented 4 months ago

like ctrl + v: sending ctrl with global mode with Hardware .eg :

await (new Hardware(0)).obj.keyboard.sendKey(["ctrl"])
await (new Virtual(handle)).obj.keyboard.sendKey(["v"]);

i am rewrite/refact some feature like this repo in rust based on deeean/sophia, see more in @yors/sophia!