加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

winapi – 在Windows上模拟Haskell的击键

发布时间:2020-12-14 02:46:23 所属栏目:Windows 来源:网络整理
导读:我正在尝试编写一个模拟 Windows上击键的Haskell程序.我试图调用keybd_event和SendInput,但都没有编译.不过,我可以用解释器来运行程序.当我在winable.h中包含对SendInput的绑定时尝试构建程序时,我收到错误: cabal install...[1 of 2] Compiling WindowsKey
我正在尝试编写一个模拟 Windows上击键的Haskell程序.我试图调用keybd_event和SendInput,但都没有编译.不过,我可以用解释器来运行程序.当我在winable.h中包含对SendInput的绑定时尝试构建程序时,我收到错误:

cabal install
...
[1 of 2] Compiling WindowsKeys      ( distbuildWindowsKeysWindowsKeys-tmpWindowsKeys.hs,distbuildWindowsKeysWindowsKeys-tmpWindowsKeys.o )
[2 of 2] Compiling Main             ( srcMain.hs,distbuildWindowsKeysWindowsKeys-tmpMain.o )
Linking distbuildWindowsKeysWindowsKeys.exe ...
distbuildWindowsKeysWindowsKeys-tmpWindowsKeys.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文件包含以下标题:

#include "windows.h"
#include "winuser.h"
#include "winable.h"

这是C绑定:

foreign import ccall unsafe "winable.h SendInput"
        c_SendInput :: UINT
                    -> Ptr Input
                    -> CInt
                    -> IO UINT

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

#if (_WIN32_WINNT >= 0x0403)
WINUSERAPI UINT WINAPI SendInput(UINT,LPINPUT,int);

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

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

谢谢!

这是WindowsKeys.cabal:

-- 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

当我注释掉键盘功能的绑定时,构建成功.

解决方法

我终于发现我使用了错误的调用约定. keybd_event和SendInput都需要使用stdcall而不是ccall来调用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读