[AccessD] SendKeys Reverse Tab

MartyConnelly martyconnelly at shaw.ca
Wed Jan 4 12:48:22 CST 2006


Or I prefer this general method " keybd_event ". Just make sure the 
proper control has focus
,if you execute this code from a command button, it will have the focus.
This also gets around SendKeys problems
Other interesting affects you can minimize all open windows with 
"Windows + M " key depression


Private Const VK_LWIN = &H5B 'Left window button
Private Const VK_RETURN = &HD  'ENTER key
Private Const VK_SHIFT = &H10 'SHIFT key
Private Const VK_CONTROL = &H11 'CTRL key
Private Const VK_MENU = &H12 'ALT key
Private Const VK_PAUSE = &H13 'PAUSE key
Private Const VK_CAPITAL = &H14 'CAPS LOCK key
Private Const VK_SNAPSHOT = &H2C  'Print Screen
Private Const VK_APPS = &H5D
         'Applications or "Windows" key on a Microsoft Natural Keyboard
'from http://support.microsoft.com/view/dev.asp?kb=242971

Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Private Const KEYEVENTF_KEYUP = &H2
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    ByVal bScan As Byte, ByVal dwflags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As 
Long) As Integer

Sub reversetab()
' You can use the same technique to programmatically "press" any other
' key, including Shift, Ctrl, Alt and keys combinations that can't be
' simulated through SendKeys
Dim ShiftState As Integer, CtrlState As Integer, AltState As Integer
'use next four lines to check for prior ctrl shift alt depression
 '       ShiftState = GetKeyState(VK_SHIFT) And &H80
 '       CtrlState = GetKeyState(VK_CONTROL) And &H80
 '       AltState = GetKeyState(VK_MENU) And &H80
'        Debug.Print ShiftState; CtrlState; AltState

    ' programmatically press the Shift key
    keybd_event vbKeyShift, 0, 0, 0
    ' then press and then release the Tab key
    keybd_event vbKeyTab, 0, 0, 0
    keybd_event vbKeyTab, 0, KEYEVENTF_KEYUP, 0
    ' and finally release the Shift Key
    keybd_event vbKeyShift, 0, KEYEVENTF_KEYUP, 0
End Sub


David McAfee wrote:

>Rather than use SendKeys which creates all sorts of fun (numlock turns off)
>
>
>Try calling MoveToPreviousControl:
>
>
>Private Sub MoveToPreviousControl()
>    If Me.ActiveControl.TabIndex = 0 Then
>        Me.Controls(Me.Controls.Count - 1).SetFocus
>    Else
>        Me.Controls(Me.ActiveControl.TabIndex - 1).SetFocus
>    End If
>End Sub
>
>Private Sub MoveToNextControl()
>    If Me.ActiveControl.TabIndex >= Me.Controls.Count - 1 Then
>        Me.Controls(0).SetFocus
>    Else
>        Me.Controls(Me.ActiveControl.TabIndex + 1).SetFocus
>    End If
>End Sub
>
>I whipped up a small sample database if you need to see a working copy
>
>David McAfee
>
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Dan Waters
>Sent: Wednesday, January 04, 2006 6:27 AM
>To: AccessD
>Subject: [AccessD] SendKeys Reverse Tab
>
>
>I'd like to use SendKeys to do a reverse Tab.  A forward tab is:
>
>    SendKeys Chr(9)
>
>How do you change this to reverse the direction?
>
>Thanks!
>Dan 
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list