vb.net检测按键 vbs检测按键是否按下
VB.net程序如何在后台判断用户按了什么键?
在窗体的on key press \ on key down事件里面判断,并根据你的限制条件决定是否show你的窗体
创新互联公司自2013年起,是专业互联网技术服务公司,拥有项目做网站、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元兴宁做网站,已为上家服务,为兴宁各地企业和个人服务,联系电话:18982081108
vb.net 怎么知道按下了多个按键
用API GetKeyboardState ,判断所有的键里哪些被按下了。
下面的是判断键盘灯的状态
Public Class NativeMethods
Private Shared keyState() As Byte
DllImport("user32.dll") _
Private Shared Function GetKeyboardState(ByVal keyState() As Byte) As Boolean
End Function
Private Shared Sub Update()
keyState = New Byte(256) {}
Dim result As Boolean = GetKeyboardState(keyState)
' Check for error:
If result = False Then
Debug.WriteLine("GetKeyBoardState error: " Marshal.GetLastWin32Error)
Throw New Exception("GetKeyBoardState error: " Marshal.GetLastWin32Error)
End If
End Sub
Public Enum LightState
Off
[On]
End Enum
' Example - the keyboard lights...
Public Shared ReadOnly Property CapsLockState() As LightState
Get
Update()
Dim isOn As Boolean = (keyState(Keys.CapsLock) = 1)
Return IIf(isOn, LightState.On, LightState.Off)
End Get
End Property
Public Shared ReadOnly Property NumLockState() As LightState
Get
Update()
Dim isOn As Boolean = (keyState(Keys.NumLock) = 1)
Return IIf(isOn, LightState.On, LightState.Off)
End Get
End Property
Public Shared ReadOnly Property ScrollLockState() As LightState
Get
Update()
Dim isOn As Boolean = (keyState(Keys.Scroll) = 1)
Return IIf(isOn, LightState.On, LightState.Off)
End Get
End Property
End Class
VB.NET 怎样识别用户按下的 Shift 按键??
这就要调用API函数了 给你代码吧 记得给点分啊
Private Const KeysM = H8000
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
Me.Text = e.KeyValue
If e.KeyValue = Keys.ShiftKey And GetAsyncKeyState(160) And KeysM Then
MsgBox("你按的是左SHIFT")
ElseIf e.KeyValue = Keys.ShiftKey And GetAsyncKeyState(161) And KeysM Then
MsgBox("你按的是右SHIFT")
End If
End Sub
利用VB.NET怎样使窗体在没有焦点时也能检测键盘事件?
窗体内检测按键
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True '注册窗体的键盘事件
End Sub
在TextBox1中显示按键代码
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
TextBox1.Text = Str(e.KeyCode) + vbCrLf
End Sub
窗体没有焦点,用窗体监测键盘输入缓冲区可以解决,但这似乎可以用于监测用户输入内容,不要用于非法目的呀!所以就是知道也不会告诉你的。
分享文章:vb.net检测按键 vbs检测按键是否按下
URL标题:http://scjbc.cn/article/hggicg.html