Using?Reader?As?StreamReader?=?New?StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,?"文本.txt"),?Encoding.Default)
創(chuàng)新互聯(lián)公司技術(shù)團(tuán)隊(duì)10年來(lái)致力于為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、高端網(wǎng)站設(shè)計(jì)、成都營(yíng)銷網(wǎng)站建設(shè)、搜索引擎SEO優(yōu)化等服務(wù)。經(jīng)過(guò)多年發(fā)展,公司擁有經(jīng)驗(yàn)豐富的技術(shù)團(tuán)隊(duì),先后服務(wù)、推廣了1000+網(wǎng)站,包括各類中小企業(yè)、企事單位、高校等機(jī)構(gòu)單位。
Dim?a,?b,?c,?d,?f?As?String
a?=?Reader.ReadLine
b?=?Reader.ReadLine
c?=?Reader.ReadLine
d?=?Reader.ReadLine
f?=?Reader.ReadLine
End?Using
用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
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each Item As Control In Controls
If TypeOf Item Is Button Then
AddHandler Item.Click, AddressOf Buts
End If
Next
End Sub
Sub Buts(ByVal sender As System.Object, ByVal e As System.EventArgs)
AllE_D(False)
Timer1.Interval = 60000
Timer1.Enabled = True
End Sub
Sub AllE_D(ByVal e_d As Boolean)
For Each Item As Control In Controls
Item.Enabled = e_d
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
AllE_D(True)
End Sub
1、將窗口的KeyPreview屬性設(shè)置為True
Me.KeyPreview = True
2、處理窗口的KeyDown事件
Sub MainFormKeyDown(sender As Object, e As KeyEventArgs)
Select Case e.KeyCode
Case Keys.Escape
Me.button1.PerformClick
Case Keys.Enter
Me.button2.PerformClick
End Select
End Sub
首先要添加兩個(gè)窗體,假設(shè)第一個(gè)窗體名為Form1,第二個(gè)窗體名為Form2。在Form1窗體中添加個(gè)按鈕Command1。按鈕單擊事件的代碼為:
Private Sub Command1_Click()
Form2.Show '用show方法加載并且顯示名為Form2的窗體
End Sub
show 方法后面省略了兩個(gè)參數(shù)即Form2.Show 0或Form2.Show 1此參數(shù)可缺省??勺孕羞\(yùn)行驗(yàn)證
1.定義變量記錄鍵是否被按下,按下的累計(jì)時(shí)間
Dim?按下A鍵??As?Boolean
Dim?按下A鍵時(shí)間?As?Integer
2.添加一個(gè)TextBox1用于接收鍵盤事件,或者直接用窗體的鍵盤事件(確保KeyPreview為True)
在KeyDown事件中添加如下代碼:
If?e.Keycode?=?keys.A?Then?按下A鍵?=?True
在KeyUp事件中添加如下代碼:
If?e.Keycode?=?keys.A?Then?按下A鍵?=?False
3.添加一個(gè)Timer1控件,調(diào)整Timer1的Interval來(lái)決定按鍵頻率,記得要把Timer1.Enable開(kāi)啟
在Tick事件中添加如下代碼:
If?按下A鍵?=?True
按下A鍵時(shí)間+=1
Call?音量設(shè)置(按下A鍵時(shí)間?*?10)
End?If
PS:?按下的秒數(shù) =?按下A鍵時(shí)間*Timer1.Interval / 1000