首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Windows上使用Haskell模拟击键

在Windows上使用Haskell模拟击键
EN

Stack Overflow用户
提问于 2013-10-25 07:30:00
回答 1查看 312关注 0票数 5

我正在尝试写一个在Windows上模拟击键的Haskell程序。我尝试调用keybd_event和SendInput,但都没有编译。不过,我可以用解释器运行这个程序。当我尝试构建一个绑定到winable.h中的SendInput的程序时,我得到了错误:

代码语言:javascript
运行
复制
cabal install
...
[1 of 2] Compiling WindowsKeys      ( dist\build\WindowsKeys\WindowsKeys-tmp\WindowsKeys.hs, dist\build\WindowsKeys\WindowsKeys-tmp\WindowsKeys.o )
[2 of 2] Compiling Main             ( src\Main.hs, dist\build\WindowsKeys\WindowsKeys-tmp\Main.o )
Linking dist\build\WindowsKeys\WindowsKeys.exe ...
dist\build\WindowsKeys\WindowsKeys-tmp\WindowsKeys.o:fake:(.text+0x35d): undefined reference to `SendInput'
collect2: ld returned 1 exit status
cabal: Error: some packages failed to install:
WindowsKeys-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1

详细错误在http://pastebin.com/trg21N0x,但它似乎不包含任何更多线索。当我尝试使用keybd_event时,我得到了一个类似的错误。我编写的hsc文件包含以下标头:

代码语言:javascript
运行
复制
#include "windows.h"
#include "winuser.h"
#include "winable.h"

下面是C语言的绑定:

代码语言:javascript
运行
复制
foreign import ccall unsafe "winable.h SendInput"
        c_SendInput :: UINT
                    -> Ptr Input
                    -> CInt
                    -> IO UINT

我假设我不能在winuser.h上调用SendInput,因为#if:

代码语言:javascript
运行
复制
#if (_WIN32_WINNT >= 0x0403)
WINUSERAPI UINT WINAPI SendInput(UINT,LPINPUT,int);

当我为_WIN32_WINNT添加绑定时,值是0x400。

我有2012.4.0.0版本的Haskell平台。它附带了一个包含我所包含的标题的文件夹。在我的计算机上找不到任何具有相同名称的其他标头。我使用的是Windows 7专业版6.1。

谢谢!

下面是WindowsKeys.cabal:

代码语言:javascript
运行
复制
-- Initial WindowsKeys.cabal generated by cabal init.  For further 
-- documentation, see http://haskell.org/cabal/users-guide/

name:                WindowsKeys
version:             0.1.0.0
build-type:          Simple
cabal-version:       >=1.8
extra-source-files:  windows.h, winuser.h, winable.h

executable WindowsKeys
  main-is:             Main.hs
  other-modules:       WindowsKeys
  build-depends:       base ==4.5.*, Win32 ==2.2.*
  hs-source-dirs:      src
  build-tools:         hsc2hs
  extra-libraries:     user32
  include-dirs:        src

当我注释掉键盘函数的绑定时,构建就成功了。

EN

回答 1

Stack Overflow用户

发布于 2013-11-07 11:07:26

我最终发现我使用了错误的调用约定。keybd_eventSendInput都需要使用stdcall而不是ccall来调用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19578565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档