大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Using Reader As StreamReader = New StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "文本.txt"), Encoding.Default)
创新互联公司技术团队10年来致力于为客户提供成都网站建设、网站建设、高端网站设计、成都营销网站建设、搜索引擎SEO优化等服务。经过多年发展,公司拥有经验丰富的技术团队,先后服务、推广了1000+网站,包括各类中小企业、企事单位、高校等机构单位。
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 ,判断所有的键里哪些被按下了。
下面的是判断键盘灯的状态
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属性设置为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
首先要添加两个窗体,假设第一个窗体名为Form1,第二个窗体名为Form2。在Form1窗体中添加个按钮Command1。按钮单击事件的代码为:
Private Sub Command1_Click()
Form2.Show '用show方法加载并且显示名为Form2的窗体
End Sub
show 方法后面省略了两个参数即Form2.Show 0或Form2.Show 1此参数可缺省。可自行运行验证
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控件,调整Timer1的Interval来决定按键频率,记得要把Timer1.Enable开启
在Tick事件中添加如下代码:
If 按下A键 = True
按下A键时间+=1
Call 音量设置(按下A键时间 * 10)
End If
PS: 按下的秒数 = 按下A键时间*Timer1.Interval / 1000