• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

sendkey question (or other options)

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
Hotwu
Asked:
Hotwu
1 Solution
 
bobbit31Commented:
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
 
HotwuAuthor Commented:
big favor, what is the constant for backtab? then i'll give it a shot.
0
 
jmgs082598Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
bobbit31Commented:
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
 
HotwuAuthor Commented:
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
 
bobbit31Commented:
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
 
HotwuAuthor Commented:
perfect solution.
0
 
Richie_SimonettiIT OperationsCommented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now