node-ffi ffi.Library往电脑窗口的任意光标处输入内容(user32.dll)window电脑

node ffi ffi.Library往电脑窗口的任意光标处输入内容(user32.dll)window电脑

类似键盘输入法的效果

我node项目和electron项目遇到需求:控件上输入任意的文字,在其他的窗口显示。
已解决!

前提:

这是user32.dll 的API
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumwindows
electron 使用 node-ffi 调用 C++ 动态链接库(DLL)
引入各种环境和架包毕竟你要调系统的C++的内容肯定需要编译的

npm install --global --production windows-build-tools
npm install -g node-gyp
装Python v2.7; 不能装>=3版本,否则编译不通过
npm install ffi
npm install ref
npm install electron-rebuild
npm run rebuild 操作即可完成electron的重编译。
cd进入node_modules/ffi目录执行如下
node-gyp rebuild --target=2.0.4 --arch=x64 --dist-url=https://npm.taobao.org/mirrors/atom/

遇到问题:

一开始我是这么写的。有问题,进去确认是发出去了消息,但是记事本、word、 资源管理器、等没有收到。所以没显示出来。

const ffi=require("ffi");
const ref = require('ref')
const path = require('path');
setTimeout(()=>{
   
		//let user32 = path.resolve('resources/dll/user32.dll');
		const Dlls = ffi.Library('user32.dll', {
   
			 'GetActiveWindow':['int',[]],
			 'GetFocus':['int',[]],
			 'ReleaseCapture':['bool',[]],
			 'GetForegroundWindow':['int',[]],
			 'SetForegroundWindow':['bool',['int']],
			 'SetActiveWindow':['bool',['int']],
			 'UpdateWindow':['bool',['int']],
			 'BringWindowToTop':['int',['int']],
			 'SetFocus':['int',['int']],
			 'ShowWindow':['int', ['int','int']],
			 'keybd_event':['void',['int','int','int','int']
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值