create on screen keyboard

joeluvrol

New member
Joined
Oct 15, 2007
Messages
1
Programming Experience
Beginner
I have been looking in the webs for days but cant find anything that i can really use. I need to create a on screen keyboard on my forms, that upon click, it will represent the as if i click from the keyboards. I need to use it so that it can function as words filtering purpose in my apps. If i just input text to the textboxes, it will not work , so i need to use the physical keyboard. so my on screen kb must fuction exactly like the actually one. Please help me wif the ways, so sample code.. or any thing that you think might be useful to my problem.Thanks a million in advance
 
Just set the text property of the button to what you want, e.g. "A", when the user clicks the button what ever textbox is selected append the buttons text property to it.
 
http://www.vbforums.com/showthread.php?t=459890

Here are some additional classes I used in the finished product.
VB.NET:
''' <summary>
''' A check box control that cannot receive focus.
''' </summary>
Public Class UnselectableCheckBox
    Inherits System.Windows.Forms.CheckBox

#Region " Constructors "

    ''' <summary>
    ''' Initialises a new instance of the <see cref="UnselectableCheckBox"/> class.
    ''' </summary>
    Public Sub New()
        MyBase.New()

        'The check box cannot receive focus.
        Me.SetStyle(ControlStyles.Selectable, False)
    End Sub

#End Region 'Constructors

#Region " Methods "

    Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
        MyBase.OnClick(e)
    End Sub

#End Region 'Methods

End Class
VB.NET:
''' <summary>
''' A check box control that raises double-click events.
''' </summary>
Public Class DoubleClickableCheckBox
    Inherits Wedderburn.Windows.Forms.UnselectableCheckBox

#Region " Variables "

    ''' <summary>
    ''' Indicates whether the <see cref="Click"/> event should be suppressed.
    ''' </summary>
    Private suppressClick As Boolean = False
    ''' <summary>
    ''' Indicates whether the <see cref="MouseClick"/> event should be suppressed.
    ''' </summary>
    Private suppressMouseClick As Boolean = False

#End Region 'Variables

#Region " Constructors "

    ''' <summary>
    ''' Initialises a new instance of the <see cref="DoubleClickableCheckBox"/> class.
    ''' </summary>
    Public Sub New()
        MyBase.New()

        'The check box raises double-click events.
        Me.SetStyle(ControlStyles.StandardClick, True)
        Me.SetStyle(ControlStyles.StandardDoubleClick, True)
    End Sub

#End Region 'Constructors

#Region " Methods "

    ''' <summary>
    ''' Overriden.  Raises the <see cref="Click"/> event.
    ''' </summary>
    ''' <param name="e">
    ''' An <see cref="EventArgs"/> that contains the event data.
    ''' </param>
    ''' <remarks>
    ''' When the <see cref="ControlStyles">StandardClick</see> and <b>StandardDoubleClick</b> control styles are set the check box will, by default, raise two <b>Click</b> events each time it is clicked.  This method suppresses the second event.
    ''' </remarks>
    Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
        If Not Me.suppressClick Then
            MyBase.OnClick(e)
        End If

        Me.suppressClick = Not Me.suppressClick
    End Sub

    ''' <summary>
    ''' Overriden.  Raises the <see cref="DoubleClick"/> event.
    ''' </summary>
    ''' <param name="e">
    ''' An <see cref="EventArgs"/> that contains the event data.
    ''' </param>
    ''' <remarks>
    ''' When the <see cref="ControlStyles">StandardClick</see> and <b>StandardDoubleClick</b> control styles are set the check box will, by default, raise a <see cref="Click"/> event after each <b>DoubleClick</b> event.  This method suppresses that <b>Click</b> event.
    ''' </remarks>
    Protected Overrides Sub OnDoubleClick(ByVal e As System.EventArgs)
        Me.suppressClick = True
        MyBase.OnDoubleClick(e)
    End Sub

    ''' <summary>
    ''' Overriden.  Raises the <see cref="MouseClick"/> event.
    ''' </summary>
    ''' <param name="e">
    ''' An <see cref="MouseEventArgs"/> that contains the event data.
    ''' </param>
    ''' <remarks>
    ''' When the <see cref="ControlStyles">StandardClick</see> and <b>StandardDoubleClick</b> control styles are set the check box will, by default, raise two <b>MouseClick</b> events each time it is clicked.  This method suppresses the second event.
    ''' </remarks>
    Protected Overrides Sub OnMouseClick(ByVal e As System.Windows.Forms.MouseEventArgs)
        If Not Me.suppressMouseClick Then
            MyBase.OnMouseClick(e)
        End If

        Me.suppressMouseClick = Not Me.suppressMouseClick
    End Sub

    ''' <summary>
    ''' Overriden.  Raises the <see cref="MouseDoubleClick"/> event.
    ''' </summary>
    ''' <param name="e">
    ''' An <see cref="MouseEventArgs"/> that contains the event data.
    ''' </param>
    ''' <remarks>
    ''' When the <see cref="ControlStyles">StandardClick</see> and <b>StandardDoubleClick</b> control styles are set the check box will, by default, raise a <see cref="MouseClick"/> event after each <b>MouseDoubleClick</b> event.  This method suppresses that <b>MouseClick</b> event.
    ''' </remarks>
    Protected Overrides Sub OnMouseDoubleClick(ByVal e As System.Windows.Forms.MouseEventArgs)
        Me.suppressMouseClick = True
        MyBase.OnMouseDoubleClick(e)
    End Sub

#End Region 'Methods

End Class
VB.NET:
''' <summary>
''' A button that represents a key on the keyboard.
''' </summary>
Public Class KeyboardButton
    Inherits Wedderburn.Windows.Forms.UnselectableButton

#Region " Variables "

    ''' <summary>
    ''' The value output when the key is pressed.
    ''' </summary>
    Private _keyOutput As String

#End Region 'Variables

#Region " Properties "

    ''' <summary>
    ''' Gets or sets the value output when the key is pressed.
    ''' </summary>
    ''' <value>
    ''' A <b>String</b> containing the value corresponding to the equivalent keyboard key.
    ''' </value>
    ''' <remarks>
    ''' Passing the value of this property to the <see cref="System.Windows.Forms.SendKeys.Send">SendKeys.Send</see> method has the equivalent effect to pressing the corresponding key on the physical keyboard.
    ''' </remarks>
    <Category("Behavior"), _
    Description("The string sent to SendKeys.Send when the key is pressed.")> _
    Public Property KeyOutput() As String
        Get
            Return Me._keyOutput
        End Get
        Set(ByVal value As String)
            Me._keyOutput = value
        End Set
    End Property

#End Region 'Properties

End Class
VB.NET:
''' <summary>
''' A button that represents a key on the keyboard whose behaviour can change when the Shift key is depressed.
''' </summary>
Friend MustInherit Class ShiftableKeyButton
    Inherits Wedderburn.Windows.Forms.KeyboardButton

#Region " Variables "

    ''' <summary>
    ''' Indicates whether the Shift key is depressed.
    ''' </summary>
    Private _shift As Boolean = False

#End Region 'Variables

#Region " Properties "

    ''' <summary>
    ''' Gets or sets a value that indicates whether the Shift key is depressed.
    ''' </summary>
    ''' <value>
    ''' <b>True</b> if the Shift key is depressed and the button's behaviour should reflect that; otherwise, <b>False</b>.
    ''' </value>
    ''' <remarks>
    ''' The property can be set externally but only derived classes can get the property value.
    ''' </remarks>
    Public Property Shift() As Boolean
        Protected Get
            Return Me._shift
        End Get
        Set(ByVal value As Boolean)
            If Me._shift <> value Then
                Me._shift = value
                Me.SetText()
            End If
        End Set
    End Property

#End Region 'Properties

#Region " Methods "

    ''' <summary>
    ''' Sets the text displayed on the button based on the state of modifier keys.
    ''' </summary>
    Protected MustOverride Sub SetText()

#End Region 'Methods

End Class
VB.NET:
''' <summary>
''' Represents a key on the keyboard that outputs a letter of the alphabet.
''' </summary>
Friend Class AlphabetKeyButton
    Inherits Wedderburn.Windows.Forms.OnScreenKeyboard.ShiftableKeyButton

#Region " Variables "

    ''' <summary>
    ''' Indicates whether the Caps Lock key is depressed.
    ''' </summary>
    Private _capsLock As Boolean

#End Region 'Variables

#Region " Properties "

    ''' <summary>
    ''' Sets a value indicating whether the Caps Lock key is depressed.
    ''' </summary>
    ''' <value>
    ''' <b>True</b> if the Caps Lock key is depressed and the button's behaviour should reflect that; otherwise, <b>False</b>.
    ''' </value>
    Public WriteOnly Property CapsLock() As Boolean
        Set(ByVal value As Boolean)
            If Me._capsLock <> value Then
                Me._capsLock = value
                Me.SetText()
            End If
        End Set
    End Property

#End Region 'Properties

#Region " Methods "

    ''' <summary>
    ''' Overridden.  Sets the casing of the text displayed on the button based on the Caps Lock and Shift key states.
    ''' </summary>
    ''' <remarks>
    ''' The text is displayed in upper case if one and only one of the Caps Lock and Shift keys are depressed.
    ''' </remarks>
    Protected Overrides Sub SetText()
        Dim upperCase As Boolean = Me._capsLock Xor Me.Shift

        If upperCase Then
            Me.Text = Me.Text.ToUpper()
        Else
            Me.Text = Me.Text.ToLower()
        End If
    End Sub

#End Region 'Methods

End Class
VB.NET:
''' <summary>
''' Represents a key on the keyboard that displays a different value if the Shift key is depressed.
''' </summary>
Friend Class DualValueKeyButton
    Inherits Wedderburn.Windows.Forms.OnScreenKeyboard.ShiftableKeyButton

#Region " Variables "

    ''' <summary>
    ''' The text displayed on the button when the Shift key is depressed.
    ''' </summary>
    Private _shiftText As String
    ''' <summary>
    ''' The text displayed on the button when the Shift key is released.
    ''' </summary>
    Private standardText As String

#End Region 'Variables

#Region " Properties "

    ''' <summary>
    ''' Gets or sets the text that is displayed on the button when the Shift key is depressed.
    ''' </summary>
    ''' <value>
    ''' A <b>String</b> containing the button text when the Shift key is depressed.
    ''' </value>
    <Category("Appearance"), _
    Description("The text displayed on the button when the Shift key is depressed.")> _
    Public Property ShiftText() As String
        Get
            Return Me._shiftText
        End Get
        Set(ByVal value As String)
            Me._shiftText = value
        End Set
    End Property

#End Region 'Properties

#Region " Methods "

    ''' <summary>
    ''' Overridden.  Sets the button text based on whether the Shift key is depressed.
    ''' </summary>
    Protected Overrides Sub SetText()
        If Me.Shift Then
            If Me.Text <> Me._shiftText Then
                'Remember the standard text and display the shift text.
                Me.standardText = Me.Text
                Me.Text = Me._shiftText
            End If
        Else
            If Me.Text <> Me.standardText Then
                'Restore the standard text.
                Me.Text = Me.standardText
            End If
        End If
    End Sub

#End Region 'Methods

End Class
 
Back
Top