-
I want to produce an on-screen keyboard as a component
that could be used from the toolbox.
When user presses a key the corresponding character should
be inserted in the control that have focus - without
affecting focus.
Question is:
How could I put chars in the keyboad buffer just as if they where inserted from keyboard and without affecting which control having focus?
-
ok, here is an example:
Code:
Private Sub cmdA_click ()
SendKeys "{A}"
End sub
is that what you need?
-
Ok-that takes care of the text input, but unfortunately
it takes the focus of the subject that should have the text.
-
Actually, Sendkeys can be used to type in regular text.
Code:
SendKeys "Text is going wherever the focus is"
That what you wanted?
-
I think he means that the former control loses its focus, then he doesn't know which one to send the keys to. If this is the case, then just store the control that lost the focus in a variable.
Put the following in a Form with 3 TextBoxes and a CommandButton.
Code:
'Store the last control in a variable
Dim LastControl As Control
Private Sub Command1_Click()
LastControl.SetFocus 'Give the focus to the lastcontrol
SendKeys "A"
End Sub
Private Sub Text1_LostFocus()
Set LastControl = Text1
End Sub
Private Sub Text2_LostFocus()
Set LastControl = Text2
End Sub
Private Sub Text3_LostFocus()
Set LastControl = Text3
End Sub
-
Well I guess that it is a way to do it.
But what I really wanted was that the keyboard component should keep track of which object that has lost the focus and who to give it back to after a "virtual key" is pressed
So there should be a minimum of extra code to implement the virtual keyboard.
Thanks anyway.
-
megatron's way is the only way i can think of, unless you incorporate a timer.