| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2929 人关注过本帖
标题:难道是有鬼在操作我的键盘
只看楼主 加入收藏
tangleiqin
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-5-19
收藏
 问题点数:0 回复次数:37 
难道是有鬼在操作我的键盘

我用VB编了一个模拟按键的程序,其实是在网上找的代码,那段代码是在驱动的级别上模拟按键的。
用了几次后,键盘上的数字键1键2键3键(大键盘的,其他的数字也有时候也不好按)不能按了,字母
键都没问题。我把键盘插到别的机器上,键盘可以正常使用,然后把别的键盘插在我的机器上,别的键盘
也可以使用。那么不是键盘问题,也不是接口问题。

当我按不动1 2 3的时候,我按下4键或其他的大键盘的数字键,就又可以按1 2 3 了。
请问下各位,这是怎么回事啊,驱动也没什么问题了,因为已经重装系统啦。



又或者是这个键盘不配这个主板了??

附上这个程序的代码:
Private Declare Function MapPhysToLin Lib "WinIo.dll" (ByVal PhysAddr As Long, ByVal PhysSize As Long, ByRef PhysMemHandle) As Long
Private Declare Function UnmapPhysicalMemory Lib "WinIo.dll" (ByVal PhysMemHandle, ByVal LinAddr) As Boolean
Private Declare Function GetPhysLong Lib "WinIo.dll" (ByVal PhysAddr As Long, ByRef PhysVal As Long) As Boolean
Private Declare Function SetPhysLong Lib "WinIo.dll" (ByVal PhysAddr As Long, ByVal PhysVal As Long) As Boolean
Private Declare Function GetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByRef PortVal As Long, ByVal bSize As Byte) As Boolean
Private Declare Function SetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByVal PortVal As Long, ByVal bSize As Byte) As Boolean
Private Declare Function InitializeWinIo Lib "WinIo.dll" () As Boolean
Private Declare Function ShutdownWinIo Lib "WinIo.dll" () As Boolean
Private Declare Function InstallWinIoDriver Lib "WinIo.dll" (ByVal DriverPath As String, ByVal Mode As Integer) As Boolean
Private Declare Function RemoveWinIoDriver Lib "WinIo.dll" () As Boolean

' ------------------------------------以上是WINIO函数声明-------------------------------------------
Private Const KBC_KEY_CMD = &H64 '键盘命令端口
Private Const KBC_KEY_DATA = &H60 '键盘数据端口
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Public VK_A As Long

'-----------------------------------以上是WIN32 API函数声明-----------------------------------------
Sub KBCWait4IBE() '等待键盘缓冲区为空
Dim dwVal As Long
Do
GetPortVal &H64, dwVal, 1
'这句表示从&H64端口读取一个字节并把读出的数据放到变量dwVal中
'GetPortVal函数的用法是GetPortVal 端口号,存放读出数据的变量,读入的长度
Loop While (dwVal And &H2)
End Sub

Private Sub Command1_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
Command1.Enabled = False
Command2.Enabled = True
Label1.ForeColor = &H80FF&
Label1.FontSize = 12
Label1.Caption = "模拟按键开始。。。"
End Sub

Private Sub Command2_Click()
Command2.Enabled = False
Command1.Enabled = True
Timer1.Enabled = False
Label1.ForeColor = &HFF&
Label1.Caption = "模拟按键结束。。。"
Text1.Enabled = True
Text1.Text = ""
End Sub

Private Sub Command3_Click()
Dim a
Dim b
Dim i As Integer
a = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
b = Array("&H41", "&H42", "&H43", "&H44", "&H45", "&H46", "&H47", "&H48", "&H49", "&H4A", "&H4B", "&H4C", "&H4D", "&H4E", "&H4F", "&H50", "&H51", "&H52", "&H53", "&H54", "&H55", "&H56", "&H57", "&H58", "&H59", "&H5a", "&H60", "&H61", "&H62", "&H63", "&H64", "&H65", "&H66", "&H67", "&H68", "&H69")
For i = 0 To 35 Step 1
If Text1.Text = a(i) Then
VK_A = b(i)
End If
Next i
Text1.Enabled = False
End Sub

Private Sub Form_Load()
Command2.Enabled = False
If InitializeWinIo = False Then
'用InitializeWinIo函数加载驱动程序,如果成功会返回true,否则返回false
MsgBox "驱动程序加载失败!"
Unload Me
End If
Timer1.Enabled = False
End Sub
Sub MyKeyDown(ByVal vKeyCoad As Long)
'这个用来模拟按下键,参数vKeyCoad传入按键的虚拟码
Dim btScancode As Long
btScancode = MapVirtualKey(vKeyCoad, 0)

KBCWait4IBE '发送数据前应该先等待键盘缓冲区为空
SetPortVal KBC_KEY_CMD, &HD2, 1 '发送键盘写入命令
'SetPortVal函数用于向端口写入数据,它的用法是SetPortVal 端口号,欲写入的数据,写入数据的长度
KBCWait4IBE
SetPortVal KBC_KEY_DATA, btScancode, 1 '写入按键信息,按下键

End Sub

Sub MyKeyUp(ByVal vKeyCoad As Long)
'这个用来模拟释放键,参数vKeyCoad传入按键的虚拟码
Dim btScancode As Long
btScancode = MapVirtualKey(vKeyCoad, 0)

KBCWait4IBE '等待键盘缓冲区为空
SetPortVal KBC_KEY_CMD, &HD2, 1 '发送键盘写入命令
KBCWait4IBE
SetPortVal KBC_KEY_DATA, (btScancode Or &H80), 1 '写入按键信息,释放键

End Sub

Private Sub Form_Unload(Cancel As Integer)
ShutdownWinIo '程序结束时记得用ShutdownWinIo函数卸载驱动程序
End Sub
Private Sub Timer1_Timer()
MyKeyDown VK_A
MyKeyUp VK_A
End Sub


这个是工程和可执行文件


[此贴子已经被作者于2007-10-5 0:03:50编辑过]

附件: 游客没有浏览附件的权限,请 登录注册
搜索更多相关主题的帖子: 键盘 
2007-10-04 23:05
f74108
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-12
收藏
得分:0 

不知道。。。。。 我找了一些代码 都不好用

2007-10-04 23:08
coachard
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:1251
专家分:0
注 册:2007-8-12
收藏
得分:0 
是的,午夜凶铃找上来啦~~~~~~~

偶学编程,也许本身就是一个错。。。
2007-10-04 23:14
tangleiqin
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-5-19
收藏
得分:0 

都别开玩笑啦,想想这个咋整

2007-10-04 23:32
china25qd
Rank: 1
等 级:新手上路
帖 子:161
专家分:0
注 册:2007-9-6
收藏
得分:0 
嘿嘿,LZ小心啊!"黑伞叔叔"看着你呢?

抱膝怀天下 闲坐观四海
2007-10-04 23:35
coachard
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:1251
专家分:0
注 册:2007-8-12
收藏
得分:0 
你还不如把整个工程发上来,让大家试试。。。

看看什么不会出现类似问题。不然这种问题是不会有结果的~~~~~

偶学编程,也许本身就是一个错。。。
2007-10-04 23:36
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
收藏
得分:0 

自己执生


Repeat  Life=Study;Until (death);
2007-10-04 23:38
simaty
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-10-4
收藏
得分:0 
复杂
2007-10-04 23:57
tangleiqin
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-5-19
收藏
得分:0 
工程发上来啦,大家看看是怎么回事。
2007-10-05 00:04
突然空闲
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-10-5
收藏
得分:0 
哈哈,,晚上睡觉的时候小心点啊。。

2007-10-05 00:47
快速回复:难道是有鬼在操作我的键盘
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021456 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved