不使用 DLL 获取按键状态函数
我需要 vb.net Getkeystate Function() 的代码,而不使用任何 DLL。我是从 vb 到 vb.net 的 API 转换的初学者。在 vb6 中,他们使用 user32 DLL。在 Vb.Net 中,我需要调用 Getkeystate 函数而不需要“ User32.dll”函数。谁能在不使用dll的情况下将代码发给我? 有没有办法在不使用 vb.net 中的 dll Getkeystate 函数的情况下获取按键状态?如果有任何人知道等效的方法,请告诉我该代码。该代码应该在 .net 框架中使用。
VB:
Private Declare Function GetKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As Integer
Dim keystate As Long
keystate = GetKeyState(27)
MsgBox keystate
VB.net
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
On Error Resume Next
Dim KeyState As Long
KeyState = GetAsyncKeyState(17)
MsgBox(KeyState
I need codes for vb.net Getkeystate Function() without using any DLL.I'm beginner for API Conversion from vb to vb.net.In vb6 they using user32 DLL.In Vb.Net i need to call Getkeystate Function without that "User32.dll" function. can any one post me the codes without using dll?
Is there any way to get key state without using that dll Getkeystate function in vb.net..? if equivalent is any one know means show me that codes.that codes should be work with in .net framework.
vb:
Private Declare Function GetKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As Integer
Dim keystate As Long
keystate = GetKeyState(27)
MsgBox keystate
vb.net
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
On Error Resume Next
Dim KeyState As Long
KeyState = GetAsyncKeyState(17)
MsgBox(KeyState
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您要么需要调用 Windows API,要么不需要 - 从您的问题中我不确定您是否理解使用 DLL/调用 Windows API 的含义。 User32.dll是Windows的一部分,调用其中的函数实际上是要求Windows为您执行函数。您想要替换该函数还是仅仅将调用转换为 vb.net?
如果您只需将调用转换为 vb.net,您可以使用 PInvoke 对 Windows API 的调用。
这是该页面的示例:
You either need to call the windows API or not - and I'm not sure from your question you understand what using the DLL/invoking the windows API means. User32.dll is part windows and calling a function within it is actually asking windows to perform function for you. Do you want to replace the function or merely convert the call to vb.net?
If all you need to just convert the call to vb.net you can use a PInvoke call to the windows API.
here's a sample from that page:
对于 17,Control (Ctrl) 键,请使用
My.Computer.Keyboard.CtrlKeyDown
。您还可以使用 System.Windows.Forms.Control.ModifierKeys 或使用 Keyboard 类。但是,使用
My
命名空间要容易得多。对于 27、Escape (Esc) 键,必须使用 Windows API 调用。请参阅 http://msdn.microsoft 上的
GetKeyState
函数。 com/en-us/library/ms646301.aspxSystem.Windows.Form.Form 并不真正需要检查 Esc。只需添加一个“取消”按钮并设置表单的
CancelButton
属性即可。如果您需要更多控制,请处理 Key 事件之一;KeyUp
、KeyDown
、KeyPress
或PreviewKeyDown
。For 17, the Control (Ctrl) key, use
My.Computer.Keyboard.CtrlKeyDown
.You can also use
System.Windows.Forms.Control.ModifierKeys
or use theKeyboard
class. But, it is much easier to use theMy
namespace.For 27, The Escape (Esc) key, you must use the Windows API call. See
GetKeyState
function at http://msdn.microsoft.com/en-us/library/ms646301.aspxChecking for Esc is not really needed with a System.Windows.Form.Form. Just add a "cancel" button and set the form's
CancelButton
property. If you need more control, then handle the one of the Key events;KeyUp
,KeyDown
,KeyPress
, orPreviewKeyDown
.