Solved

sendkey question (or other options)

Posted on 2002-06-24
8
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

724 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