Results 1 to 19 of 19

Thread: Building Blocks for an On-screen Keyboard

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Building Blocks for an On-screen Keyboard

    I'm creating an on-screen keyboard at the moment to be integrated into an application intended for use on touch-screens. I haven't completed it yet and I'm not necessarily going to post the finished product, but here are the building blocks: a form and a button that will not receive focus. Just note that this behaviour applies to the client area of the form only. If the the user clicks the non-client area, i.e. the title bar and border, then the form will take the focus. This behaviour is just like the in-built Windows OSK.
    vb.net Code:
    1. ''' <summary>
    2. ''' A button control that cannot receive focus.
    3. ''' </summary>
    4. Public Class UnselectableButton
    5.     Inherits System.Windows.Forms.Button
    6.  
    7. #Region " Constructors "
    8.  
    9.     ''' <summary>
    10.     ''' Initialises a new instance of the <see cref="UnselectableButton"/> class.
    11.     ''' </summary>
    12.     Public Sub New()
    13.         MyBase.New()
    14.  
    15.         'The button cannot receive focus.
    16.         Me.SetStyle(ControlStyles.Selectable, False)
    17.     End Sub
    18.  
    19. #End Region 'Constructors
    20.  
    21. #Region " Variables "
    22.  
    23.     ''' <summary>
    24.     ''' Corresponds to the MA_NOACTIVATE window process reply.
    25.     ''' </summary>
    26.     Private Shared ReadOnly noActivate As New IntPtr(NativeConstants.MA_NOACTIVATE)
    27.  
    28. #End Region 'Variables
    29.  
    30. #Region " Methods "
    31.  
    32.     ''' <summary>
    33.     ''' Processes Windows messages.
    34.     ''' </summary>
    35.     ''' <remarks>
    36.     ''' Informs Windows not to activate the window when it is clicked with the mouse.  Note that this behaviour applies to the client area of the window only.
    37.     ''' </remarks>
    38.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    39.         MyBase.WndProc(m)
    40.  
    41.         If m.Msg = NativeConstants.WM_MOUSEACTIVATE Then
    42.             'Tell Windows not to activate the window on a mouse click.
    43.             m.Result = noActivate
    44.         End If
    45.     End Sub
    46.  
    47.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    48.         MyBase.OnClick(e)
    49.     End Sub
    50.  
    51. #End Region 'Methods
    52.  
    53. End Class
    Last edited by jmcilhinney; Oct 9th, 2007 at 03:34 AM. Reason: Removed buggy form code. See post #3 for final code.

  2. #2

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    Hmmm... that form works within the current application but it messes up if you try to "type" into another application. I'll do some more research and post back when I have a solution.

  3. #3

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    Here's the final code for the form:
    vb Code:
    1. ''' <summary>
    2. ''' A form that is not activated when clicked with the mouse.
    3. ''' </summary>
    4. Public Class UnselectableForm
    5.     Inherits System.Windows.Forms.Form
    6.  
    7. #Region " Properties "
    8.  
    9.     ''' <summary>
    10.     ''' This member overrides <see cref="System.Windows.Forms.Form.CreateParams">Form.CreateParams</see>.
    11.     ''' </summary>
    12.     Protected Overrides ReadOnly Property CreateParams() As CreateParams
    13.         Get
    14.             Dim value As CreateParams = MyBase.CreateParams
    15.  
    16.             'Don't allow the window to be activated.
    17.             value.ExStyle = value.ExStyle Or NativeConstants.WS_EX_NOACTIVATE
    18.             Return value
    19.         End Get
    20.     End Property
    21.  
    22. #End Region 'Properties
    23.  
    24. #Region " Methods "
    25.  
    26.     ''' <summary>
    27.     ''' Displays the form to the user without activating it.
    28.     ''' </summary>
    29.     Public Overloads Sub ShowUnactivated()
    30.         NativeMethods.ShowWindow(Me.Handle, NativeConstants.SW_SHOWNOACTIVATE)
    31.     End Sub
    32.  
    33.     ''' <summary>
    34.     ''' Displays the form with the specified owner to the user without activating it.
    35.     ''' </summary>
    36.     ''' <param name="owner">
    37.     ''' The top-level window that will own this form.
    38.     ''' </param>
    39.     Public Overloads Sub ShowUnactivated(ByVal owner As Form)
    40.         Me.Owner = owner
    41.         Me.ShowUnactivated()
    42.     End Sub
    43.  
    44.     ''' <summary>
    45.     ''' This member overrides <see cref="System.Windows.Forms.Form.WndProc">Form.WndProc</see>.
    46.     ''' </summary>
    47.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    48.         If m.Msg = NativeConstants.WM_MOUSEACTIVATE Then
    49.             'Tell Windows not to activate the window on a mouse click.
    50.             m.Result = CType(NativeConstants.MA_NOACTIVATE, IntPtr)
    51.         Else
    52.             MyBase.WndProc(m)
    53.         End If
    54.     End Sub
    55.  
    56. #End Region 'Methods
    57.  
    58. End Class
    Here are the constant declarations:
    vb Code:
    1. ''' <summary>
    2. ''' Contains Win32 constant declarations.
    3. ''' </summary>
    4. Friend NotInheritable Class NativeConstants
    5.  
    6.     ''' <summary>
    7.     ''' Specifies that a window cannot be activated.
    8.     ''' </summary>
    9.     ''' <remarks>
    10.     ''' If a child window has this style, clicking it does not cause its top-level parent to activate. Although a window that has this style will still receive mouse events, neither it nor its child windows can get the focus.
    11.     ''' </remarks>
    12.     Public Const WS_EX_NOACTIVATE As Integer = &H8000000
    13.  
    14.     ''' <summary>
    15.     ''' This message is sent when the cursor is in an inactive window and the user presses a mouse button.
    16.     ''' </summary>
    17.     Public Const WM_MOUSEACTIVATE As Integer = &H21
    18.  
    19.     ''' <summary>
    20.     ''' Does not activate the window, and does not discard the mouse message.
    21.     ''' </summary>
    22.     ''' <remarks>
    23.     ''' This is one of the possible return values when the <see cref="WM_MOUSEACTIVATE"/> notification is received.
    24.     ''' </remarks>
    25.     Public Const MA_NOACTIVATE As Integer = 3
    26.  
    27.     ''' <summary>
    28.     ''' Displays a window in its most recent size and position. This value is similar to <b>SW_SHOWNORMAL</b>, except the window is not actived.
    29.     ''' </summary>
    30.     ''' <remarks>
    31.     ''' This is one of the possible values for the <b>nCmdShow</b> argument of the <see cref="NativeMethods.ShowWindow">ShowWindow</see> method.
    32.     ''' </remarks>
    33.     Public Const SW_SHOWNOACTIVATE As Integer = 4
    34.  
    35. End Class
    Here is the ShowWindow declaration:
    vb Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Friend NotInheritable Class NativeMethods
    4.  
    5.     ''' <summary>
    6.     ''' This function sets the specified window's show state.
    7.     ''' </summary>
    8.     ''' <param name="hWnd">
    9.     ''' Handle to the window.
    10.     ''' </param>
    11.     ''' <param name="nCmdShow">
    12.     ''' <para>Specifies how the window is to be shown.</para>
    13.     ''' <para>
    14.     ''' This parameter can be one of the following values.
    15.     ''' <b>SW_FORCEMINIMIZE</b>
    16.     '''    Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread.
    17.     ''' <b>SW_HIDE</b>
    18.     '''    Hides the window and activates another window.
    19.     ''' <b>SW_MAXIMIZE</b>
    20.     '''    Maximizes the specified window.
    21.     ''' <b>SW_MINIMIZE</b>
    22.     '''    Minimizes the specified window and activates the next top-level window in the Z order.
    23.     ''' <b>SW_RESTORE</b>
    24.     '''   Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
    25.     ''' <b>SW_SHOW</b>
    26.     '''   Activates the window and displays it in its current size and position.
    27.     ''' <b>SW_SHOWDEFAULT</b>
    28.     '''   Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
    29.     ''' <b>SW_SHOWMAXIMIZED</b>
    30.     '''   Activates the window and displays it as a maximized window.
    31.     ''' <b>SW_SHOWMINIMIZED</b>
    32.     '''   Activates the window and displays it as a minimized window.
    33.     ''' <b>SW_SHOWMINNOACTIVE</b>
    34.     '''   Displays the window as a minimized window. This value is similar to <b>SW_SHOWMINIMIZED</b>, except the window is not activated.
    35.     ''' <b>SW_SHOWNA</b>
    36.     '''   Displays the window in its current size and position. This value is similar to <b>SW_SHOW</b>, except the window is not activated.
    37.     ''' <see cref="NativeConstants.SW_SHOWNOACTIVATE">SW_SHOWNOACTIVATE</see>
    38.     '''   Displays a window in its most recent size and position. This value is similar to <b>SW_SHOWNORMAL</b>, except the window is not actived.
    39.     ''' <b>SW_SHOWNORMAL</b>
    40.     '''   Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
    41.     ''' </para>
    42.     ''' </param>
    43.     ''' <returns>
    44.     ''' True if the window was previously visible; otherwise, False.
    45.     ''' </returns>
    46.     <DllImport("user32")> _
    47.     Public Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
    48.     End Function
    49.  
    50. End Class

  4. #4

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    Here are some additional classes:
    vb.net Code:
    1. ''' <summary>
    2. ''' Represents a key on the keyboard that displays a different value if the Shift key is depressed.
    3. ''' </summary>
    4. Friend Class DualValueKeyButton
    5.     Inherits ShiftableKeyButton
    6.  
    7. #Region " Variables "
    8.  
    9.     ''' <summary>
    10.     ''' The text displayed on the button when the Shift key is depressed.
    11.     ''' </summary>
    12.     Private _shiftText As String
    13.     ''' <summary>
    14.     ''' The text displayed on the button when the Shift key is released.
    15.     ''' </summary>
    16.     Private standardText As String
    17.  
    18. #End Region 'Variables
    19.  
    20. #Region " Properties "
    21.  
    22.     ''' <summary>
    23.     ''' Gets or sets the text that is displayed on the button when the Shift key is depressed.
    24.     ''' </summary>
    25.     ''' <value>
    26.     ''' A <b>String</b> containing the button text when the Shift key is depressed.
    27.     ''' </value>
    28.     <Category("Appearance"), _
    29.     Description("The text displayed on the button when the Shift key is depressed.")> _
    30.     Public Property ShiftText() As String
    31.         Get
    32.             Return Me._shiftText
    33.         End Get
    34.         Set(ByVal value As String)
    35.             Me._shiftText = value
    36.         End Set
    37.     End Property
    38.  
    39. #End Region 'Properties
    40.  
    41. #Region " Methods "
    42.  
    43.     ''' <summary>
    44.     ''' Overridden.  Sets the button text based on whether the Shift key is depressed.
    45.     ''' </summary>
    46.     Protected Overrides Sub SetText()
    47.         If Me.Shift Then
    48.             If Me.Text <> Me._shiftText Then
    49.                 'Remember the standard text and display the shift text.
    50.                 Me.standardText = Me.Text
    51.                 Me.Text = Me._shiftText
    52.             End If
    53.         Else
    54.             If Me.Text <> Me.standardText Then
    55.                 'Restore the standard text.
    56.                 Me.Text = Me.standardText
    57.             End If
    58.         End If
    59.     End Sub
    60.  
    61. #End Region 'Methods
    62.  
    63. End Class
    vb.net Code:
    1. ''' <summary>
    2. ''' Represents a key on the keyboard that outputs a letter of the alphabet.
    3. ''' </summary>
    4. Friend Class AlphabetKeyButton
    5.     Inherits ShiftableKeyButton
    6.  
    7. #Region " Variables "
    8.  
    9.     ''' <summary>
    10.     ''' Indicates whether the Caps Lock key is depressed.
    11.     ''' </summary>
    12.     Private _capsLock As Boolean
    13.  
    14. #End Region 'Variables
    15.  
    16. #Region " Properties "
    17.  
    18.     ''' <summary>
    19.     ''' Sets a value indicating whether the Caps Lock key is depressed.
    20.     ''' </summary>
    21.     ''' <value>
    22.     ''' <b>True</b> if the Caps Lock key is depressed and the button's behaviour should reflect that; otherwise, <b>False</b>.
    23.     ''' </value>
    24.     Public WriteOnly Property CapsLock() As Boolean
    25.         Set(ByVal value As Boolean)
    26.             If Me._capsLock <> value Then
    27.                 Me._capsLock = value
    28.                 Me.SetText()
    29.             End If
    30.         End Set
    31.     End Property
    32.  
    33. #End Region 'Properties
    34.  
    35. #Region " Methods "
    36.  
    37.     ''' <summary>
    38.     ''' Overridden.  Sets the casing of the text displayed on the button based on the Caps Lock and Shift key states.
    39.     ''' </summary>
    40.     ''' <remarks>
    41.     ''' The text is displayed in upper case if one and only one of the Caps Lock and Shift keys are depressed.
    42.     ''' </remarks>
    43.     Protected Overrides Sub SetText()
    44.         Dim upperCase As Boolean = Me._capsLock Xor Me.Shift
    45.  
    46.         If upperCase Then
    47.             Me.Text = Me.Text.ToUpper()
    48.         Else
    49.             Me.Text = Me.Text.ToLower()
    50.         End If
    51.     End Sub
    52.  
    53. #End Region 'Methods
    54.  
    55. End Class
    vb.net Code:
    1. ''' <summary>
    2. ''' A button that represents a key on the keyboard whose behaviour can change when the Shift key is depressed.
    3. ''' </summary>
    4. Friend MustInherit Class ShiftableKeyButton
    5.     Inherits KeyboardButton
    6.  
    7. #Region " Variables "
    8.  
    9.     ''' <summary>
    10.     ''' Indicates whether the Shift key is depressed.
    11.     ''' </summary>
    12.     Private _shift As Boolean = False
    13.  
    14. #End Region 'Variables
    15.  
    16. #Region " Properties "
    17.  
    18.     ''' <summary>
    19.     ''' Gets or sets a value that indicates whether the Shift key is depressed.
    20.     ''' </summary>
    21.     ''' <value>
    22.     ''' <b>True</b> if the Shift key is depressed and the button's behaviour should reflect that; otherwise, <b>False</b>.
    23.     ''' </value>
    24.     ''' <remarks>
    25.     ''' The property can be set externally but only derived classes can get the property value.
    26.     ''' </remarks>
    27.     Public Property Shift() As Boolean
    28.         Protected Get
    29.             Return Me._shift
    30.         End Get
    31.         Set(ByVal value As Boolean)
    32.             If Me._shift <> value Then
    33.                 Me._shift = value
    34.                 Me.SetText()
    35.             End If
    36.         End Set
    37.     End Property
    38.  
    39. #End Region 'Properties
    40.  
    41. #Region " Methods "
    42.  
    43.     ''' <summary>
    44.     ''' Sets the text displayed on the button based on the state of modifier keys.
    45.     ''' </summary>
    46.     Protected MustOverride Sub SetText()
    47.  
    48. #End Region 'Methods
    49.  
    50. End Class
    vb.net Code:
    1. ''' <summary>
    2. ''' A button that represents a key on the keyboard.
    3. ''' </summary>
    4. Public Class KeyboardButton
    5.     Inherits UnselectableButton
    6.  
    7. #Region " Variables "
    8.  
    9.     ''' <summary>
    10.     ''' The value output when the key is pressed.
    11.     ''' </summary>
    12.     Private _keyOutput As String
    13.  
    14. #End Region 'Variables
    15.  
    16. #Region " Properties "
    17.  
    18.     ''' <summary>
    19.     ''' Gets or sets the value output when the key is pressed.
    20.     ''' </summary>
    21.     ''' <value>
    22.     ''' A <b>String</b> containing the value corresponding to the equivalent keyboard key.
    23.     ''' </value>
    24.     ''' <remarks>
    25.     ''' 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.
    26.     ''' </remarks>
    27.     <Category("Behavior"), _
    28.     Description("The string sent to SendKeys.Send when the key is pressed.")> _
    29.     Public Property KeyOutput() As String
    30.         Get
    31.             Return Me._keyOutput
    32.         End Get
    33.         Set(ByVal value As String)
    34.             Me._keyOutput = value
    35.         End Set
    36.     End Property
    37.  
    38. #End Region 'Properties
    39.  
    40. End Class

  5. #5

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    And some more:
    vb.net Code:
    1. ''' <summary>
    2. ''' A check box control that raises double-click events.
    3. ''' </summary>
    4. Public Class DoubleClickableCheckBox
    5.     Inherits UnselectableCheckBox
    6.  
    7. #Region " Variables "
    8.  
    9.     ''' <summary>
    10.     ''' Indicates whether the <see cref="Click"/> event should be suppressed.
    11.     ''' </summary>
    12.     Private suppressClick As Boolean = False
    13.     ''' <summary>
    14.     ''' Indicates whether the <see cref="MouseClick"/> event should be suppressed.
    15.     ''' </summary>
    16.     Private suppressMouseClick As Boolean = False
    17.  
    18. #End Region 'Variables
    19.  
    20. #Region " Constructors "
    21.  
    22.     ''' <summary>
    23.     ''' Initialises a new instance of the <see cref="DoubleClickableCheckBox"/> class.
    24.     ''' </summary>
    25.     Public Sub New()
    26.         MyBase.New()
    27.  
    28.         'The check box raises double-click events.
    29.         Me.SetStyle(ControlStyles.StandardClick, True)
    30.         Me.SetStyle(ControlStyles.StandardDoubleClick, True)
    31.     End Sub
    32.  
    33. #End Region 'Constructors
    34.  
    35. #Region " Methods "
    36.  
    37.     ''' <summary>
    38.     ''' Overriden.  Raises the <see cref="Click"/> event.
    39.     ''' </summary>
    40.     ''' <param name="e">
    41.     ''' An <see cref="EventArgs"/> that contains the event data.
    42.     ''' </param>
    43.     ''' <remarks>
    44.     ''' 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.
    45.     ''' </remarks>
    46.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    47.         If Not Me.suppressClick Then
    48.             MyBase.OnClick(e)
    49.         End If
    50.  
    51.         Me.suppressClick = Not Me.suppressClick
    52.     End Sub
    53.  
    54.     ''' <summary>
    55.     ''' Overriden.  Raises the <see cref="DoubleClick"/> event.
    56.     ''' </summary>
    57.     ''' <param name="e">
    58.     ''' An <see cref="EventArgs"/> that contains the event data.
    59.     ''' </param>
    60.     ''' <remarks>
    61.     ''' 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.
    62.     ''' </remarks>
    63.     Protected Overrides Sub OnDoubleClick(ByVal e As System.EventArgs)
    64.         Me.suppressClick = True
    65.         MyBase.OnDoubleClick(e)
    66.     End Sub
    67.  
    68.     ''' <summary>
    69.     ''' Overriden.  Raises the <see cref="MouseClick"/> event.
    70.     ''' </summary>
    71.     ''' <param name="e">
    72.     ''' An <see cref="MouseEventArgs"/> that contains the event data.
    73.     ''' </param>
    74.     ''' <remarks>
    75.     ''' 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.
    76.     ''' </remarks>
    77.     Protected Overrides Sub OnMouseClick(ByVal e As System.Windows.Forms.MouseEventArgs)
    78.         If Not Me.suppressMouseClick Then
    79.             MyBase.OnMouseClick(e)
    80.         End If
    81.  
    82.         Me.suppressMouseClick = Not Me.suppressMouseClick
    83.     End Sub
    84.  
    85.     ''' <summary>
    86.     ''' Overriden.  Raises the <see cref="MouseDoubleClick"/> event.
    87.     ''' </summary>
    88.     ''' <param name="e">
    89.     ''' An <see cref="MouseEventArgs"/> that contains the event data.
    90.     ''' </param>
    91.     ''' <remarks>
    92.     ''' 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.
    93.     ''' </remarks>
    94.     Protected Overrides Sub OnMouseDoubleClick(ByVal e As System.Windows.Forms.MouseEventArgs)
    95.         Me.suppressMouseClick = True
    96.         MyBase.OnMouseDoubleClick(e)
    97.     End Sub
    98.  
    99. #End Region 'Methods
    100.  
    101. End Class
    vb.net Code:
    1. ''' <summary>
    2. ''' A check box control that cannot receive focus.
    3. ''' </summary>
    4. Public Class UnselectableCheckBox
    5.     Inherits System.Windows.Forms.CheckBox
    6.  
    7. #Region " Constructors "
    8.  
    9.     ''' <summary>
    10.     ''' Initialises a new instance of the <see cref="UnselectableCheckBox"/> class.
    11.     ''' </summary>
    12.     Public Sub New()
    13.         MyBase.New()
    14.  
    15.         'The check box cannot receive focus.
    16.         Me.SetStyle(ControlStyles.Selectable, False)
    17.     End Sub
    18.  
    19. #End Region 'Constructors
    20.  
    21. #Region " Methods "
    22.  
    23.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    24.         MyBase.OnClick(e)
    25.     End Sub
    26.  
    27. #End Region 'Methods
    28.  
    29. End Class

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Building Blocks for an On-screen Keyboard

    Hi Jhon,
    It will be good , if we have attachement as we have in your other projects.

    Thanks
    Dana
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    The end result of this was for my employer, so I'm not willing to do that.

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Building Blocks for an On-screen Keyboard

    I'm curious as to why you needed to build one rather than using the built in one for Windows. Was there something yours did that Osk didn't?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  9. #9

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    Quote Originally Posted by kasracer
    I'm curious as to why you needed to build one rather than using the built in one for Windows. Was there something yours did that Osk didn't?
    The Windows OSK is very small and not so great if you're doing everything with it. It's really intended for use with the mouse rather than on a touchscreen. My OSK was larger and less susceptible to "fat finger syndrome". It also matched the rest of my UI, including colour themes defined and controlled within the app. Finally, with the click of a button my OSK was shown occupying a predefined height across the full width of the screen and the application window was resized to occupy the rest. Clicking the same button again would hide the OSK and remaximise the app window. This was a POS application that was designed to be the only thing running on the system; almost like a kiosk.

  10. #10
    New Member
    Join Date
    Jul 2008
    Posts
    2

    Re: Building Blocks for an On-screen Keyboard

    Hi Everyone! I hope someone can help me! Has anyone got this running in a project that they can sent to me? It would be very very much appreciated!!

    I have one that works with another window but this one is perfect for what i need..

    Thanks in advance
    Anthony

  11. #11
    Addicted Member
    Join Date
    Dec 2011
    Posts
    194

    Re: Building Blocks for an On-screen Keyboard

    @jmcilhinney

    I have started new project and added 4 classes NativeMethods, NativeConstants, UnselectableForm and UnselectableButton then opened UnselectableForm and draw UnselectableButton and some other standard controls, when i run the project, i see the form empty.

    check the attachment, what's wrong i did?
    Attached Files Attached Files
    Last edited by Absolute_Zero; Jul 1st, 2013 at 05:13 PM.

  12. #12

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    Quote Originally Posted by Absolute_Zero View Post
    @jmcilhinney

    I have started new project and added 4 classes NativeMethods, NativeConstants, UnselectableForm and UnselectableButton then opened UnselectableForm and draw UnselectableButton and some other standard controls, when i run the project, i see the form empty.

    check the attachment, what's wrong i did?
    You shouldn't touch UnselectableForm. It should be a base class only. When you create your own forms, you derive them from UnselectableForm instead of Form. If your IDE supports it (not sure that Express does) you can select the Inherited Form item template when adding a new form. Otherwise, create the form as normal and then change the base class in the code afterwards.

    You can add UnselectableButton controls to a form from the Toolbox, just like any other control. It will be added to the Toolbox automatically when you build.

  13. #13
    Addicted Member
    Join Date
    Dec 2011
    Posts
    194

    Re: Building Blocks for an On-screen Keyboard

    you can select the Inherited Form item template when adding a new form.
    Thanks, it works.

    Is it possible to make the form got the focus when click on its title bar? Currently i have to minimize and restore to make it focused.

  14. #14

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    Quote Originally Posted by Absolute_Zero View Post
    Thanks, it works.

    Is it possible to make the form got the focus when click on its title bar? Currently i have to minimize and restore to make it focused.
    As I said back in post #1 of this thread, that's exactly how it works by default. I just tested in VS 2012 and it worked that way as well. You must be doing something else. Here are the steps I took:

    1. Created a new WinForms Application project.
    2. Added NativeConstants, NativeMethods, UnselectableForm and UnselectableButton classes to the project and copied in the code from this thread.
    3. Built the project.
    4. Added a new Inherited Form item to the project and selected UnselectableForm as the base.
    5. Added three UnselectableButton controls to the new form (Form2).
    6. Added a Button and a TextBox to the original form (Form1).
    7. Added this code to Form1:
    vb.net Code:
    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2.     Call New Form2().ShowUnactivated()
    3. End Sub
    8. Added this code to Form2:
    vb.net Code:
    1. Private Sub UnselectableButton1_Click(sender As Object, e As EventArgs) Handles UnselectableButton1.Click
    2.     SendKeys.Send("A")
    3. End Sub
    4.  
    5. Private Sub UnselectableButton2_Click(sender As Object, e As EventArgs) Handles UnselectableButton2.Click
    6.     SendKeys.Send("B")
    7. End Sub
    8.  
    9. Private Sub UnselectableButton3_Click(sender As Object, e As EventArgs) Handles UnselectableButton3.Click
    10.     SendKeys.Send("C")
    11. End Sub
    9. Ran the project.
    10. Clicked Button1 on Form1.

    At this stage, Form2 was displayed but did not take focus. If I clicked on the Form2's client area or a button then it did not take focus but it did take focus if I clicked in the title bar or border. If I clicked in the TextBox on Form1 and then clicked on the buttons on Form2, I would see ABC characters appear in the TextBox.

  15. #15
    Addicted Member
    Join Date
    Dec 2011
    Posts
    194

    Re: Building Blocks for an On-screen Keyboard

    If I clicked on the Form2's client area or a button then it did not take focus but it did take focus if I clicked in the title bar or border.
    That's true when both form are belong to the same App, but what i ask for is switch the focus to the form when i came from different App, e.g. Notepad

    Any help?

  16. #16

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    Quote Originally Posted by Absolute_Zero View Post
    That's true when both form are belong to the same App, but what i ask for is switch the focus to the form when i came from different App, e.g. Notepad

    Any help?
    Perhaps you could provide a set of steps to reproduce your issue, something like I went to the trouble of doing for you in post #14.

  17. #17
    Addicted Member
    Join Date
    Dec 2011
    Posts
    194

    Re: Building Blocks for an On-screen Keyboard

    It is easy,

    1- Run the project you have created in pos #14 and show Form2
    2- Set the focus to any other App, e.g. Notepad (not maximized so you can see the both)
    3- Click on Form2 title bar but it is not focused.

  18. #18

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Building Blocks for an On-screen Keyboard

    Quote Originally Posted by Absolute_Zero View Post
    It is easy,

    1- Run the project you have created in pos #14 and show Form2
    2- Set the focus to any other App, e.g. Notepad (not maximized so you can see the both)
    3- Click on Form2 title bar but it is not focused.
    Hmmm... now I see what you mean. I don't recall having seen that behaviour previously but I'm not sure whether I just never tried to focus the window by clicking the title bar while another application had focus. I might test it on an older version of VS when I get home. Not sure what the solution would be but it might be either, because the window receives the same message and returns the same result whether the window that currently has focus is part of the same application or not.

  19. #19
    Addicted Member
    Join Date
    Dec 2011
    Posts
    194

    Re: Building Blocks for an On-screen Keyboard

    I have googled a lot for a solution but couldn't find any, and ended with this
    Code:
    Option Strict On
    Option Explicit On
    
    Public Class UnselectableForm
        Inherits System.Windows.Forms.Form
        Private Const WS_EX_NOACTIVATE As Integer = &H8000000L
    
        Protected Overrides ReadOnly Property CreateParams() As CreateParams
            Get
                Dim value As CreateParams = MyBase.CreateParams
                value .ExStyle = value .ExStyle Or WS_EX_NOACTIVATE
                Return value
            End Get
        End Property
    End Class
    I don't see any reason for overriding WndProc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width