Solved

sendkey question (or other options)

Posted on 2002-06-24
8
230 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

21 Experts available now in Live!

Get 1:1 Help Now