gpt4 book ai didi

node.js - GetCursorPos Node FFI - 如何通过 ref 获取指针返回

转载 作者:太空宇宙 更新时间:2023-11-04 03:28:56 24 4
gpt4 key购买 nike

我编写了以下代码来设置键盘光标位置。但得到垃圾。任何线索,我错过了什么?

var ffi = require('ffi');
var ref = require('ref');
var Struct = require('ref-struct');

var point = Struct({
'x': 'long',
'y': 'long'
});
var user32 = ffi.Library('user32.dll', {
GetCaretPos:['bool',[locPtr]]
});
var pbuf = new point();
caretpos = user32.GetCaretPos(pbuf);

console.log(":",pbuf.x );

接下来,我尝试了以下方法,但效果不佳。

var ffi = require('ffi');
var ref = require('ref');
var Struct = require('ref-struct');

var voidPtr = ref.refType(ref.types.void);
var user32 = ffi.Library('user32.dll', {
GetCaretPos:['bool',[voidPtr]]
});
var pbuf = new Buffer(2);
caretpos = user32.GetCaretPos(pbuf);
var cpos =(new Uint8Array(pbuf));
console.log(">",cpos ); //Doesn't work **> Uint8Array [ 0, 0, 0, 0 ]**

最佳答案

如文章标题所示“GetCursorPos in Node FFI”并返回指针 x,y

下面的代码对我有用,它是获取 x,y 指针的 hack。

var ffi = require('ffi');
var repbuffer = new Buffer(16); // holder for windows structures
var user32 = ffi.Library('user32.dll', {
'GetCursorPos':['bool',['pointer']]
});
//Show mouse cords at console every sec
setInterval( function() { getmousepos();}, 1000);
function getmousepos(){
var p = user32.GetCursorPos(repbuffer);
var x= repbuffer[0]+ (repbuffer[1]*256);
var y= repbuffer[4]+(repbuffer[5]*256);
console.log(x + " " + y);
}

关于node.js - GetCursorPos Node FFI - 如何通过 ref 获取指针返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40727596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com