-
vb教程之用VB5.0收集键盘和鼠标信息
陈耀华
在一些应用软件中,收集键盘和鼠标的信息比较重要,而VB5.0又没有提供相应的函数达到这个目的。实际上可以用相应的API来实现,如笔者的键盘信息为:键盘类型:IBM 101/102增强键盘,重复击键速度每秒钟15个字符,键盘延时0秒,光标闪烁间隔500ms;鼠标为MS双键,双击间隔为300ms。运行以下程序就可以收集到以上信息。
程序代码:
建立一模块,命名为info.bas,API声明如下:
Option Explicit
′搜集键盘信息的API
Declare Function GetCaretBlinkTime Lib ″user32″ () As Long
Public Const SPI—GETKEYBOARDSPEED = 10
Public Const SPI—GETKEYBOARDDELAY = 22
Declare Function SystemParametersInfo Lib ″user32″ Alias ″SystemParametersInfoA″ (ByVal uAction As Long,
ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Declare Function GetKeyboardType Lib ″user32″ (ByVal nTypeFlag As Long) As Long
′搜集鼠标信息的API
Declare Function GetDoubleClickTime Lib ″user32″ () As Long
Public Const SM—CMOUSEBUTTONS = 43
Declare Function GetSystemMetrics Lib ″user32″ (ByVal nIndex As Long) As Long
Public Const SM—MOUSEPRESENT = 19
主窗口(Form1)上放Command1,Timer1及4个label,分别命名为lblkeyboard,lblrepeatspeed,lblrepeatdelay,lblcaretflash.显示键盘的信息建一shape1,表示光标闪烁的效果。2个label,分别命为lblmouse,lbldblclick显示鼠标的信息。
Private Sub Command1—Click()
Dim r As Long
Dim t As String
Dim k As Long
Dim q As Long
k = GetKeyboardType(0)
If k = 1 Then t = ″PC or compatible 83-key keyboard″
If k = 2 Then t = ″Olivetti 102-key keyboard″
If k = 3 Then t = ″AT or compatible 84-key keyboard″
If k = 4 Then t = ″Enhanced(IBM) 101-102-key keyboard″
If k = 5 Then t = ″Nokia 1050 keyboard″
If k = 6 Then t = ″Nokia 9140 keyboard″
If k = 7 Then t = ″Japanese keyboard″
lblkeyboard = ′Type of keyboard : ″ & t
q = SystemParametersInfo(SPI—GETKEYBOARDDELAY, 0, r, 0)
lblrepeatdelay = ″Keyboard Repeat Delay = ″ & r & ″ Seconds″
q = SystemParametersInfo(SPI—GETKEYBOARDSPEED, 0, r, 0)
scrRepeatSpeed = r
lblrepeatspeed = ″Keyboard Repeat Speed = ″ & r & ″ characters per second.″
Timer1.Interval = GetCaretBlinkTime
scrCaretFlash = GetCaretBlinkTime
lblcaretflash = ″Caret Flash Speed = ″ & GetCaretBlinkTime & ″ms″
If GetSystemMetrics(SM_MOUSEPRESENT) = 1 Then
lblmouse = ″Standard Mouse Present with ″ & GetSystemMetrics(SM—CMOUSEBUTTONS) & ″ buttons.″
Else
lblmouse = ″No Mouse Present.″
Exit Sub
End If
lbldblclick = ″Double Click Speed = ″ & GetDoubleClickTime & ″ms″
End Sub
Private Sub Form—Load()
Call Command1—Click
End Sub
Private Sub Timer1—Timer()
Shape1.Visible = Not Shape1.Visible
End Sub
按F5运行,点击Command1即可收集到键盘和鼠标信息。
此程序在Pwin95和中文VB5.0中成功运行通过,已运用到实际工作中。
在一些应用软件中,收集键盘和鼠标的信息比较重要,而VB5.0又没有提供相应的函数达到这个目的。实际上可以用相应的API来实现,如笔者的键盘信息为:键盘类型:IBM 101/102增强键盘,重复击键速度每秒钟15个字符,键盘延时0秒,光标闪烁间隔500ms;鼠标为MS双键,双击间隔为300ms。运行以下程序就可以收集到以上信息。
程序代码:
建立一模块,命名为info.bas,API声明如下:
Option Explicit
′搜集键盘信息的API
Declare Function GetCaretBlinkTime Lib ″user32″ () As Long
Public Const SPI—GETKEYBOARDSPEED = 10
Public Const SPI—GETKEYBOARDDELAY = 22
Declare Function SystemParametersInfo Lib ″user32″ Alias ″SystemParametersInfoA″ (ByVal uAction As Long,
ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Declare Function GetKeyboardType Lib ″user32″ (ByVal nTypeFlag As Long) As Long
′搜集鼠标信息的API
Declare Function GetDoubleClickTime Lib ″user32″ () As Long
Public Const SM—CMOUSEBUTTONS = 43
Declare Function GetSystemMetrics Lib ″user32″ (ByVal nIndex As Long) As Long
Public Const SM—MOUSEPRESENT = 19
主窗口(Form1)上放Command1,Timer1及4个label,分别命名为lblkeyboard,lblrepeatspeed,lblrepeatdelay,lblcaretflash.显示键盘的信息建一shape1,表示光标闪烁的效果。2个label,分别命为lblmouse,lbldblclick显示鼠标的信息。
Private Sub Command1—Click()
Dim r As Long
Dim t As String
Dim k As Long
Dim q As Long
k = GetKeyboardType(0)
If k = 1 Then t = ″PC or compatible 83-key keyboard″
If k = 2 Then t = ″Olivetti 102-key keyboard″
If k = 3 Then t = ″AT or compatible 84-key keyboard″
If k = 4 Then t = ″Enhanced(IBM) 101-102-key keyboard″
If k = 5 Then t = ″Nokia 1050 keyboard″
If k = 6 Then t = ″Nokia 9140 keyboard″
If k = 7 Then t = ″Japanese keyboard″
lblkeyboard = ′Type of keyboard : ″ & t
q = SystemParametersInfo(SPI—GETKEYBOARDDELAY, 0, r, 0)
lblrepeatdelay = ″Keyboard Repeat Delay = ″ & r & ″ Seconds″
q = SystemParametersInfo(SPI—GETKEYBOARDSPEED, 0, r, 0)
scrRepeatSpeed = r
lblrepeatspeed = ″Keyboard Repeat Speed = ″ & r & ″ characters per second.″
Timer1.Interval = GetCaretBlinkTime
scrCaretFlash = GetCaretBlinkTime
lblcaretflash = ″Caret Flash Speed = ″ & GetCaretBlinkTime & ″ms″
If GetSystemMetrics(SM_MOUSEPRESENT) = 1 Then
lblmouse = ″Standard Mouse Present with ″ & GetSystemMetrics(SM—CMOUSEBUTTONS) & ″ buttons.″
Else
lblmouse = ″No Mouse Present.″
Exit Sub
End If
lbldblclick = ″Double Click Speed = ″ & GetDoubleClickTime & ″ms″
End Sub
Private Sub Form—Load()
Call Command1—Click
End Sub
Private Sub Timer1—Timer()
Shape1.Visible = Not Shape1.Visible
End Sub
按F5运行,点击Command1即可收集到键盘和鼠标信息。
此程序在Pwin95和中文VB5.0中成功运行通过,已运用到实际工作中。
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比