用API函數(shù),以下代碼Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比榆次網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式榆次網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋榆次地區(qū)。費(fèi)用合理售后完善,十年實體公司更值得信賴。
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPrivate Const WS_EX_LAYERED = H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = H2
Private Const LWA_COLORKEY = H1Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMosT = -1
Private Const SWP_NOMOVE = H2
Private Const SWP_NosIZE = H1
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_KEYDOWN = H100
Const WM_KEYUP = H101
Const WM_CHAR = H102
Const VK_F1 = H70
Private Sub SendF1(hwnd) '調(diào)用這個過程即可對目標(biāo)窗體發(fā)送F1鍵
Call PostMessage(hwnd, WM_KEYDOWN, VK_F1, 0)
Call PostMessage(hwnd, WM_KEYUP, VK_F1, 0)
End Sub這里是發(fā)送F1的實例,各個按鍵對應(yīng)的虛擬鍵碼,要到網(wǎng)上查
在該按紐的單擊事件編寫代碼:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
在VB6的時候,使用:Unload me
在VB.NET里使用:Me.Close()
VB.NET即時窗口用于在設(shè)計時調(diào)試和計算表達(dá)式、執(zhí)行語句、輸出變量值等
快捷鍵是:CTRL+G 或者按 CTRL+ALT+I
Public Sub TextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
Dim SplitStr As String = ","
Dim SelectionStart As Integer = sender.SelectionStart
Dim TextLength As Integer = sender.Text.Length
'------------------------------------------------------------------
Select Case Asc(e.KeyChar)
Case Is = 8 '"回刪"
Dim str As String = sender.text
Dim Array = Split(sender.text, ",", -1)
If sender.SelectionStart = str.Length Then
If str.Contains(",") Then
Dim text = ""
For x = 0 To UBound(Array) - 1
If text = "" Then
text += Array(x)
Else
text += "," + Array(x)
End If
Next
sender.text = text
sender.SelectionStart = text.Length
e.KeyChar = Chr(0)
End If
End If
Case Asc("0") To Asc("9") '" 0 to 9 "
e.KeyChar = e.KeyChar
Case Is = 44, 45 '","
Select Case TextLength
Case Is = 0
e.KeyChar = Chr(0)
Case Else
Select Case SelectionStart
Case 0
e.KeyChar = Chr(0)
Case 1 To TextLength - 1
If Mid(sender.text, SelectionStart, 1) = SplitStr Or Mid(sender.text, SelectionStart + 1, 1) = SplitStr Then
e.KeyChar = Chr(0)
Else
e.KeyChar = e.KeyChar
End If
Case TextLength
If Mid(sender.text, SelectionStart, 1) = SplitStr Then
e.KeyChar = Chr(0)
Else
e.KeyChar = e.KeyChar
End If
End Select
End Select
Case Else
e.KeyChar = Chr(0)
End Select
End Sub
這是我的程序中復(fù)制過來的,只能輸入數(shù)據(jù)字與逗號還有下劃線,你查一下F和J的Ass嗎是多少,改寫一下就OK
新建一個Form1把Form1的KeyPreview改成True
拖入一個Button1到Form1上面
然后加入以下代碼
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyData = (Keys.Alt Or Keys.G) Then
Button1.PerformClick() '或者用Button1_Click(Nothing, New EventArgs)
'快捷鍵Alt+G觸發(fā)Button1_Click()事件。
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Size = New Size(180, 23)
Button1.Text = "我被局部快捷鍵給召喚了~"
End Sub
1.定義變量記錄鍵是否被按下,按下的累計時間
Dim?按下A鍵??As?Boolean
Dim?按下A鍵時間?As?Integer
2.添加一個TextBox1用于接收鍵盤事件,或者直接用窗體的鍵盤事件(確保KeyPreview為True)
在KeyDown事件中添加如下代碼:
If?e.Keycode?=?keys.A?Then?按下A鍵?=?True
在KeyUp事件中添加如下代碼:
If?e.Keycode?=?keys.A?Then?按下A鍵?=?False
3.添加一個Timer1控件,調(diào)整Timer1的Interval來決定按鍵頻率,記得要把Timer1.Enable開啟
在Tick事件中添加如下代碼:
If?按下A鍵?=?True
按下A鍵時間+=1
Call?音量設(shè)置(按下A鍵時間?*?10)
End?If
PS:?按下的秒數(shù) =?按下A鍵時間*Timer1.Interval / 1000