nodejs 调用win32 api
生活随笔
收集整理的這篇文章主要介紹了
nodejs 调用win32 api
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
win32 api
也可以試試我寫(xiě)的 node-windows-x64 庫(kù)
>node -v
v12.16.1
>npm install -g node-gyp
>npm i @saleae/ffi
>node test.js
1
test.js
const ffi = require("@saleae/ffi");
// Convert JSString to CString
function TEXT(text) {
return Buffer.from(`${text}`, "ucs2");
}
// Import user32
const user32 = new ffi.Library("user32", {
// 返回值類(lèi)型,參數(shù)列表類(lèi)型
MessageBoxW: ["int32", ["int32", "string", "string", "int32"]],
SetCursorPos: ["bool", ["int32", "int32"]],
});
const OK_or_Cancel = user32.MessageBoxW(0, TEXT("Hello from Node.js!"), TEXT("Hello, World!"), 1);
console.log(OK_or_Cancel);
// user32.SetCursorPos(0, 0);
獲取窗口句柄
const ffi = require("@saleae/ffi");
// Convert JSString to CString
function TEXT(text) {
return Buffer.from(`${text}`, "ucs2");
}
// Import user32
const user32 = new ffi.Library("user32", {
FindWindowW: ["int32", ["string", "string"]],
});
var hwnd = user32.FindWindowW(TEXT('Progman'), null);
console.log(hwnd); // 65814
console.log(hwnd.toString(16)); // 10116
如果你熟練win32 api 知道自己在做什么,你可以使用 node-windows-x64
install
λ npm i node-windows-x64
調(diào)用 MessageBoxA 示例
import { node_windows_x64 as nw } from "node-windows-x64";
nw["user32.messageboxa"](0, "body", "title", 2);
總結(jié)
以上是生活随笔為你收集整理的nodejs 调用win32 api的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Deep Reinforcement L
- 下一篇: [机器学习]正则化方法 -- Regul