on screen keyboard

  • Thread starter Thread starter jonathandrott
  • Start date Start date
J

jonathandrott

Hi, i'm kinda new to vb.net and i'm trying to make an on screen
keyboard to use with a touch screen. how do i get it to print a
letter on the screen when the button is pressed in the textbox that is
selected? do i do it as a ascii character?

i'm trying to get data from a user. there are a couple of different
field the user will have to type information into. (i.e. first name,
last name, .etc)
 
Hi, i'm kinda new to vb.net and i'm trying to make an on screen
keyboard to use with a touch screen. how do i get it to print a
letter on the screen when the button is pressed in the textbox that is
selected? do i do it as a ascii character?

i'm trying to get data from a user. there are a couple of different
field the user will have to type information into. (i.e. first name,
last name, .etc)

Are you trying to write a global on screen keyboard or just one to use
in your application only?

Thanks,

Seth Rowe
 
Hello Jonathan,

the easiest thing would be to raise an event which contains a variable
with the keycode or the string. However, when developing such a keyboard
(I once wrote one as an OCX, which can be downloaded from
www.henke-hk.com), please keep in mind that there are different layouts
(e.g. on German keyboards you have to press AltGr (Ctrl+Alt)+Q to get
the "@" sign). Considering that .NET supports Unicode, you might need to
consider Chinese/Japanese keyboards and their input methods as well.

Best regards,

Martin
 
it's with my application

Then the absolute easiest way would be to create a usercontrol that
will act as the keyboard. Then you just have worry about passing the
pressed key back to the "target" control.

Here's a quick sample I just wrote:

First comes the user control. For it you need to add some labels, one
for each key of the keyboard. I set the label's Textalign to
MiddleCenter and the BorderStyle to single to give it more of a key-
like look, though if this was a profession app, I would do some GDI+
work to make the label look more like a button. The reason you need to
use a label and not a button is that labels don't receive focus when
clicked.

Next, add the following code the user control. Note I changed the
inherits to Panel to prevent the usercontrol from getting focus, so
you'll have to change the inherits in the usercontrol.Designer.vb file
too.

Public Class Keyboard
Inherits Panel

' Wire up all the Label's click events to this event handler
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
OnKeyPressed(New KeyPressedEventArgs(DirectCast(sender,
Label).Text))
End Sub

Public Event KeyPressed As KeyPressedEventHandler

Protected Overridable Sub OnKeyPressed(ByVal e As
KeyPressedEventArgs)
RaiseEvent KeyPressed(Me, e)
End Sub

End Class

Public Delegate Sub KeyPressedEventHandler(ByVal sender As Object,
ByVal e As KeyPressedEventArgs)

Public Class KeyPressedEventArgs
Inherits EventArgs

Public Sub New(ByVal keyPressed As String)
Me.KeyPressed = keyPressed
End Sub

Private _KeyPressed As String
Public Property KeyPressed() As String
Get
Return _KeyPressed
End Get
Private Set(ByVal value As String)
_KeyPressed = value
End Set
End Property

End Class

That should be it for the usercontrol, now we just have to worry about
the "host" form. All you have to do is add the new keyboard
usercontrol to a form and then handle the usercontrol's new KeyPressed
event. Use something like the following:

Private Sub Keyboard1_KeyPressed(ByVal sender As System.Object,
ByVal e As KeyPressedEventArgs)
' You'll have to change this cast if you want to send text
' to a control type other than a TextBox
Dim tb As TextBox = TryCast(Me.ActiveControl, TextBox)
If Not tb Is Nothing Then
tb.Text &= e.KeyPressed
tb.SelectionStart = tb.Text.Length
End If
End Sub

Since neither the usercontrol or it's labels can get the focus, the
event handler will try to cast the active control (the control that
had focus before the user clicked the keyboard usercontrol) into a
textbox and then append the text from the KeyPressed event.

I'm guessing there is a more elegant solution to this, but at this
late at night I can't think of one :-) Anyways, I hope it helps you
out!

Thanks,

Seth Rowe
 
Back
Top