JSA里的FFI(6)——AHK_H2

wils
wils

创作者俱乐部成员

用的是黑神的库https://github.com/thqby/AutoHotkey_H


之前的帖子都是调用winapi或系统自带的dll

今天试试第三方dll,比较推荐的就是这个ahk2dll

function tt()
{
    const ahkdll = FFI.LoadLibrary(`${ThisWorkbook.Path}/AutoHotkey32.dll`)
    const NewThread = ahkdll.LoadFunction('', 'NewThread', '', 'pointer', ['u16string'])
    const ahkFunction = ahkdll.LoadFunction('', 'ahkFunction', '', 'u16string', ['u16string', 'u16string', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer'])
    const thread = NewThread.Call('Persistent\ntest(s){\nMsgBox "a😀c", s\nreturn s\n}')
    console.log(ahkFunction.Call('test', 's😀s', null, null, null, null, null, null, null, null, null, thread))
}
  • NewThread开个ahk线程,持续运行,完全不影响js这边

  • 线程里只定义了一个test函数,返回值和参数都是宽字符串

  • ahkFunction执行线程里的方法,获得返回值


dll本身的接口不多,用起来很简单

但结合ahk2的能力,可就太棒了,甚至希望官方能把这个只有1.5M的dll整合进wps,直接让wps多出一种扩展语言


这个手册有点旧但能用https://hotkeyit.github.io/v2/docs/commands/WinApi.htm

这里可以方便调用大多数常用的winapi

可以用com对象

可以设置复杂灵活的快捷键,是对鼠标键盘winapi的更好封装

可以动态生成Gui,比如日期选择框等,是对dialogbox winapi的更好封装

可以MCODE直接调用内存中用gcc编译的c方法,比如递归

还有更方便的多线程,UIAutomation,WebView2,7zip等等


这个dll包括7zip只有1.5M,却直接提供了强于VBA与JSA的另一种可能,非常推荐

海南省
浏览 208
1
8
分享
8 +1
3
1 +1
全部评论 3
 
初心不忘
看了下项目是gpl协议,那别建议了,放弃幻想
· 江苏省
1
回复
wils
wils

创作者俱乐部成员

哈哈,至少可以参考,将gui包装的方便一点
· 海南省
回复
 
恰同学少年
· 黑龙江省
回复