vb.net按键 vbnet按键程序

VB.net 怎么制作按键连发功能

用API函数,以下代码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

创新互联建站-专业网站定制、快速模板网站建设、高性价比榆次网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式榆次网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖榆次地区。费用合理售后完善,十年实体公司更值得信赖。

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) '调用这个过程即可对目标窗体发送F1键

Call PostMessage(hwnd, WM_KEYDOWN, VK_F1, 0)

Call PostMessage(hwnd, WM_KEYUP, VK_F1, 0)

End Sub这里是发送F1的实例,各个按键对应的虚拟键码,要到网上查

vb.net 如何用一个按钮(button)来关闭按钮所在的窗体

在该按纽的单击事件编写代码:

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即时窗口快捷键

VB.NET即时窗口用于在设计时调试和计算表达式、执行语句、输出变量值等

快捷键是:CTRL+G 或者按 CTRL+ALT+I

vb.net在for循环中如何获取键盘按键

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和J的Ass吗是多少,改写一下就OK

vb.net怎么设置快捷键

新建一个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触发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

vb.net的,按键连续触发事件,比如,按着键不放,音量增大。

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


分享文章:vb.net按键 vbnet按键程序
链接分享:http://hbruida.cn/article/dodjgdg.html