Can I get Keyboard data not using Controls?

  • Thread starter Thread starter Ken Soenen
  • Start date Start date
K

Ken Soenen

Is there any way I can detect a keyboard event while a Form is open, WITHOUT
having to use the keyboard event handlers from the Control that has the
Focus?

For Example:

Let's say I have Form that has only one Control, say a Textbox, and this
Textbox is DISABLED so it can't take the Focus and receive keyboard events.
Can I still somehow get the data coming from the keyboard and say, put it in
a String. Of course, if the textbox were enabled and had the focus, I would
want the data to ALSO go in the Textbox as it normally would.

Thanks for any thoughts.
 
hi, Ken !
Is there any way I can detect a keyboard event while a Form is open
WITHOUT having to use the keyboard event handlers from the Control that has the Focus?
Let's say I have Form that has only one Control, say a Textbox, and this Textbox is DISABLED
so it can't take the Focus and receive keyboard events.
Can I still somehow get the data coming from the keyboard and say put it in a String.
Of course, if the textbox were enabled and had the focus
I would want the data to ALSO go in the Textbox as it normally would...

you can get keyboard events from the form itself [assuming only one textbox control AND disabled]...
just play with other events rather double-clicking the form...
=== in the form code module ===
Dim CharsFromForm As String
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1 = CharsFromForm
CharsFromForm = ""
End Sub
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
CharsFromForm = CharsFromForm & Chr(KeyAscii)
End Sub

hth,
hector.
 
Thanks Hector. I appreciate your time spent.

Héctor Miguel said:
hi, Ken !
Is there any way I can detect a keyboard event while a Form is open
WITHOUT having to use the keyboard event handlers from the Control that
has the Focus?
Let's say I have Form that has only one Control, say a Textbox, and this
Textbox is DISABLED
so it can't take the Focus and receive keyboard events.
Can I still somehow get the data coming from the keyboard and say put it
in a String.
Of course, if the textbox were enabled and had the focus
I would want the data to ALSO go in the Textbox as it normally would...

you can get keyboard events from the form itself [assuming only one
textbox control AND disabled]...
just play with other events rather double-clicking the form...
=== in the form code module ===
Dim CharsFromForm As String
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1 = CharsFromForm
CharsFromForm = ""
End Sub
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
CharsFromForm = CharsFromForm & Chr(KeyAscii)
End Sub

hth,
hector.
 
Back
Top