Solved

sendkey question (or other options)

Posted on 2002-06-24
8
233 Views
Last Modified: 2010-05-02
i have a program that requires that the arrow keys be converted to act as tab keys moving back and forth between objects on my form.

here is some code that i picked up from msdn, but does not seem to work when moving outside of the frame with focus (moving from object to object within the fram works fine).

If Screen.ActiveControl.TabIndex = Count - 1 Then
   NextTabIndex = 0
Else
   NextTabIndex = Screen.ActiveControl.TabIndex + 1
End If
For i = 0 To Count - 1
   If Me.Controls(i).TabIndex = NextTabIndex Then
      Me.Controls(i).SetFocus
      Exit For
   End If
Next i


i have also attempted to use the sendkey function, but this for some reason has been causing the num lock key to turn off without reason (irregularly).

Call SendKeys("{TAB}") or Call SendKeys("+{TAB}")

if anyone knows of a good work around that will keep my num lock key from turning off or can provide code that will allow me to check at the end of my function if the numlock key is off and to turn it back on if it did accidentally get shut off the points will be awarded to you. thanks.

0
Comment
Question by:Hotwu
8 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 7104863
instead of using sendkeys...

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_TAB = &H9

public sub command1_click
   keybd_event VK_TAB, 0, 0, 0
end sub
0
 

Author Comment

by:Hotwu
ID: 7104876
big favor, what is the constant for backtab? then i'll give it a shot.
0
 
LVL 1

Expert Comment

by:jmgs082598
ID: 7104949
Hi Hotwu,

When you say that the sendkey function Lock the Keyboard.
Your vbapp is running in WinNT o Win2k?
I using this way:

Private Sub txt_fields_KeyPress(Index As Integer, KeyAscii As Integer)
   If KeyAscii = 13 Then
      SendKeys "{TAB}", True
      KeyAscii = 0
   end if
end sub

You have to use the True for the [wait] option.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7104975
Private Sub PressTab()
    keybd_event VK_TAB, 0, 0, 0
End Sub

Private Sub PressBackTab()
    '' press and hold shift
    keybd_event VK_SHIFT, 0, 0, 0
   
    '' press tab
    keybd_event VK_TAB, 0, 0, 0
   
    '' release shift
    keybd_event VK_SHIFT, 0, KEYEVENTF_KEYUP, 0

End Sub
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Hotwu
ID: 7105004
bobbit31 ~ so very close... exactly what i am looking for, however i am having problems with the backtab... i think that the shift key press is not in a holding state. almost as though you press it then it let's go. not sure, but the backtab function also moves me forwards just like the tab function.
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 200 total points
ID: 7105083
hrmm, make sure you have the constants correct

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_TAB = &H9
Private Const VK_SHIFT = &H10
Private Const KEYEVENTF_KEYUP = &H2

0
 

Author Comment

by:Hotwu
ID: 7105096
perfect solution.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7105136
i did try last code from Bobbit and it works.
I used two text box and a command button.
Maybe the problem is when command button gets the focus...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now