VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 使用 kb_event 函数模拟键盘操作
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:11347, 日期:2001-10-09
使用 kb_event 函数模拟键盘操作
kb_event函数的使用 
     
下面的函数可以利用kb_event实行一些系统操作


Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const VK_LWIN = &H5B
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_APPS = &H5D
Private Const VK_PLAY = &HFA

Private Sub DoAction(Index As Integer)
 Dim VK_ACTION As Long

 Select Case Index
  Case 0: 注释:打开资源管理器
   VK_ACTION = &H45
  Case 1: 注释:查找文件
   VK_ACTION = &H46
  Case 2: 注释:最小化所有窗口
   VK_ACTION = &H4D
  Case 3: 注释:运行程序
   VK_ACTION = &H52
  Case 4: 注释:弹出Win菜单
   VK_ACTION = &H5B
  Case 5: 注释:将计算机转入睡眠状态
   VK_ACTION = &H5E
  Case 6: 注释:执行Windows帮助
   VK_ACTION = &H70
 End Select

 Call keybd_event(VK_LWIN, 0, 0, 0)
 Call keybd_event(VK_ACTION, 0, 0, 0)
 Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
End Sub