MouseMove里有個參數(shù)是Button,1是左鍵按下,2是右鍵按下,4是中間按下
霞浦網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,霞浦網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為霞浦上千多家提供企業(yè)網(wǎng)站建設(shè)服務。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個售后服務好的霞浦做網(wǎng)站的公司定做!
用API ?GetKeyboardState?,判斷所有的鍵里哪些被按下了。
下面的是判斷鍵盤燈的狀態(tài)
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
這就要調(diào)用API函數(shù)了 給你代碼吧 記得給點分啊
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
窗體內(nèi)檢測按鍵
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
窗體沒有焦點,用窗體監(jiān)測鍵盤輸入緩沖區(qū)可以解決,但這似乎可以用于監(jiān)測用戶輸入內(nèi)容,不要用于非法目的呀!所以就是知道也不會告訴你的。
新聞標題:vb點虐
檢測按鍵 vbs判斷按下哪個鍵
網(wǎng)頁地址:http://jinyejixie.com/article20/ddishjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、定制網(wǎng)站、軟件開發(fā)、網(wǎng)站設(shè)計、域名注冊、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)