软件注册站
热情软件屋

 
VB为什么捕捉不到{tab}键
编号: QA002770    
建立日期: 2000年3月24日 最后修改日期: 2004年9月5日
所属类别: Visual Basic - 键盘与鼠标
   
    操作系统:Win95
    编程工具:VB6
    问题:VB 6 为什么捕捉不到{tab}键?我想捕捉{tab}键,用下面的方法不行,但同样的方法可以捕捉到其它键,如{ESC}、{enter},所用的事件和程序片段如下:
    Private Sub TextEdit_KeyPress(KeyAscii As Integer)
     If KeyAscii = 9 Then
     msgbox "This is the {tab} key."
     End If
    End Sub
    
    Private Sub TextEdit_KeyDown(KeyCode As Integer, Shift As Integer)
     If KeyCode = 9 Then
     msgbox "This is the {tab} key."
     End If
    End Sub
    按下{tab}键,以上程序不响应,为什么? 谢谢解答!!!(Chen Tuo)
   
    下面是一个捕捉Tab键的例子。由于Tab键可以触发LostFocus事件,在这个例子中使用GetKeyState函数检查是否是使用Tab键触发的事件。
    Private Declare Function GetKeyState Lib "User32" (ByVal nVirtKey As Long) As Integer
    ' Virtual key values
    Const VK_TAB = &H9
    Const VK_SHIFT = &H10
    
    Sub txtAreaCode_LostFocus()
    Dim iRetVal As Integer
    
     ' Check for a tab out of this control
     ' Skip the state field
     iRetVal = GetKeyState(VK_SHIFT)
     ' 如果没有按shift,检查tab
     If iRetVal <> -128 And iRetVal <> -127 Then
     iRetVal = GetKeyState(VK_TAB)
     If iRetVal = -128 Or iRetVal = -127 Then ' tab键按下
     txtPhone.SetFocus
     End If
     End If
    End Sub
    

    
    相关问题:
    QA001373 "如何捕捉当按下Tab键,相应事件被触发"

    

此问题由李海回答。

附加关键字:编程, 源程序, programming, source code, Visual Basic, VB, 键盘与鼠标, mouse, keyboard, hid

   
 
把这个问题推荐给朋友
   
 
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio