How can I trap Shift+tab key press action.... 
Author Message
 How can I trap Shift+tab key press action....

Could anyone help me with this problem please....
I wanna trap keypress of Shift+tab.  How can I do this??

thanks
Girija



Tue, 22 May 2001 03:00:00 GMT  
 How can I trap Shift+tab key press action....
You can probably trap this with a sendmessage api call, but a way to
programatically to it is as follows.  I assume that you don't want the
user to back tab to the previous tab setting:

Option Explicit
Dim LastKeyPressed As String

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 16 And Shift = 1 Then
        LastKeyPressed = "shift"
    End If
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    LastKeyPressed = ""
End Sub

Private Sub Text1_LostFocus()
    If LastKeyPressed = "shift" Then
        Text1.SetFocus
    End If

End Sub

Quote:

> Could anyone help me with this problem please....
> I wanna trap keypress of Shift+tab.  How can I do this??

> thanks
> Girija



Thu, 24 May 2001 03:00:00 GMT  
 How can I trap Shift+tab key press action....
You can trap Tab or Shift-Tab in the Keydown Event of a control on a form.
You can only do so when all of the controls on the form have their Tabstop
properties set to False.  You can set the Tabstops to False in the GotFocus
Event of the control where trapping will be done.  It is also necessary to
restore the Tabstops to True when focus passes to another control on the
form.  This can be done in the LostFocus Event.  The code necessary to set
the Tabstops to either True or False is in the following subroutine which
should be placed in a standard module:

Public Sub Set_Tabbing(frmName As Form, Setting As Boolean)
   Dim iIndex As Integer
   For iIndex = 0 To frmName.Controls.Count - 1
      On Error Resume Next
      frmName.Controls(iIndex).TabStop = Setting
   Next
End Sub

The following code demonstrates how trap Tab or Shift Tab in a textbox named
Text2.  To set it up, you need a form named Form1.    On Form1, place 3
textboxes named Text1, Text2, and Text3.  The tabbing order for the three
should be Text1, Text2, Text3.  The Set_Tabbing subroutine, as stated above,
goes into a standard module.

Private Sub Text2_GotFocus()
Set_Tabbing Form1, False
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab And Shift = 0 Then
   KeyCode = 0
   Msgbox "Tab trapped"
   Text3.SetFocus
ElseIf KeyCode = vbKeyTab And Shift = 1 Then
   KeyCode = 0
   Msgbox "Shift Tab"
   Text1.SetFocus
End If
End Sub

Private Sub Text2_LostFocus()
Set_Tabbing Form1, True
End Sub

The actual trapping takes place in the KeyDown Event.  The Keypress Event
works OK for Tab but not Shift-Tab.  You will notice that after trapping,
the focus is set to the next control in the tabbing order with the SetFocus
method.  It is necessary to do this to fire the LostFocus Event where normal
tabbing is restored by setting the TabStops back to True.

Hope this is what you need.
John

Quote:

>Could anyone help me with this problem please....
>I wanna trap keypress of Shift+tab.  How can I do this??

>thanks
>Girija



Mon, 28 May 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. how to trap shift-tab key

2. Capturing Tab key and Shift-Tab key

3. How to trap the TAB key press.

4. Changing the Up and down key to Tab and shift Tab

5. Why does SS Tab trap key events before the form traps them

6. Testing for Shift or Ctrl key presses during Drag and Drop

7. Determine which Shift key was pressed (Right or Left)

8. Detecting if Shift key is pressed

9. Trapping Shift-Tab

10. Help ~~ How to trap function keys ?(Alt ,Ctrl ,Shift)

11. trapping function key press

12. Trapping Funtion Key Presses

 

 
Powered by phpBB® Forum Software