使用User32.dll的SendInput [英] using SendInput of User32.dll

查看:89
本文介绍了使用User32.dll的SendInput的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 10中使用Visual Studio 2015 net 4.6并在vb和wpf中编码。

user32.dll的keybd_event的现有代码在visual studio 2010中正常工作。



I am using Windows 10 with Visual Studio 2015 net 4.6 and coding in vb and wpf.
Existing code of keybd_event of user32.dll works fine in visual studio 2010.

<DllImport("user32.dll")>
 Shared Sub keybd_event(bVk As Byte, bScan As Byte, dwFlags As UInteger, dwExtraInfo As Integer)
 End Sub









安装Community 2015后,代码分析器说

严重级代码描述项目文件行

警告CA1901正如在代码中声明的那样,P / Invoke'NativeMethods.keybd_event(字节,字节,UInteger,整数)'的参数'dwExtraInfo'在64位平台上将是4字节宽。这是不正确的,因为此API的实际本机声明表明它在64位平台上应该是8字节宽。请参阅MSDN Platform SDK文档以获取帮助,确定应该使用哪种数据类型而不是'Integer'。



我在网上搜索了解决方案。我无法了解或无法理解我现有的知识水平。我的代码仅用于我的目的而且我是新手。

不再使用keybd_event并且使用了SendInput。我试过msdn论坛,但代码不起作用。



问题是:

1.我应该使用keybd_event或SendInput

2.如果要使用keybd_event,如何纠正上面的警告。

3.如果要使用SendInput,我请求帮助获取代码。

c#代码示例也可以。

谢谢





After installing Community 2015, the code analyser says
Severity Code Description Project File Line
Warning CA1901 As it is declared in your code, parameter 'dwExtraInfo' of P/Invoke 'NativeMethods.keybd_event(Byte, Byte, UInteger, Integer)' will be 4 bytes wide on 64-bit platforms. This is not correct, as the actual native declaration of this API indicates it should be 8 bytes wide on 64-bit platforms. Consult the MSDN Platform SDK documentation for help determining what data type should be used instead of 'Integer'.

I searched web for solution. I could not get or unable to understand with my existing level of knowledge. I code only for my purposes and I am a novice.
The keybd_event is no longer used and in place SendInput is used. I tried msdn forums and the code does not work.

Question is:
1. What should I use keybd_event or SendInput
2. In case keybd_event is to be used how to rectify the warning as above.
3. if SendInput to be used, I request assistance in getting the code for the purpose.
c# code example also will do.
Thanks

推荐答案

  1. 不要使用 keybd_event 。此函数已被 SendInput 取代。请参阅此处的评论:

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx [ ^ ]
  2. 不适用;请不要使用它。
  3. 您只需要: http://www.pinvoke .net / default.aspx / user32.sendinput [ ^ ]。

    代码示例请求没有多大意义,因为您没有告诉我们您想要实现的目标。但用法非常简单,功能非常可靠;我不记得是否有任何问题。
  1. Don't use keybd_event. This function has been superseded by SendInput. See the comment here:
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^]
  2. Inapplicable; don't use it.
  3. All you need is here: http://www.pinvoke.net/default.aspx/user32.sendinput[^].
    The request for code sample makes little sense, because you did not tell us what you want to achieve. But the usage is quite trivial, and the function is very reliable; I don't remembers if it presented any problems.





-SA


这篇关于使用User32.dll的SendInput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆