Switching Input Panel into numeric mode

Last post 04-11-2008 9:04 by palewar. 16 replies.
Page 1 of 2 (17 items) 1 2 Next >
Sort Posts: Previous Next
  • 11-17-2003 18:19

    Switching Input Panel into numeric mode

    This seems to be a rather popular request. ALthough it does not look like there is an "official" API to do it, with a bit of good ol' hack you can force standard Pocket PC virtual keyboard to switch to numeric mode.

    The sample code (C#) is available from http://www.alexfeinman.com/download.asp?doc=IMSwitch.zip

    The trick is to check the color of an appropriate part (left top corner) of the virtual keyboard window and if it is not the color of window text to simulate mouse click by sending a couple of mouse messages.

    This is hack and you should use it only if you can live with it not working at some point (weird color scheme, new version fo Pocket PC, Oracle buying the Windows CE division and migrating all devices to embedded Linux, tsunamis and various other elements of typical force majeur clauses)

    Alex Feinman
    MCP
    MVP Windows Media Center
    Software Engineer
    Corrigo Inc
    CA, US
  • 01-14-2004 13:47 In reply to

    Re: Switching Input Panel into numeric mode

    Hi, Alex [:)]

    I've been attempting to convert the code to VB.NET at the request of a poster to the CF newsgroup. But I've come across a sticking point. The code seems to work fine except for the second call to GetPixel (to set the value of pixelNew). For some reason, the second call returns 248 instead of 16317688. I was wondering if you (or anyone reading this) could help me spot the error. Here's the relavent code:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If Not (InputPanel1.Enabled) Then
    InputPanel1.Enabled = True
    Application.DoEvents()
    End If

    Dim clsidKbdIM As New Guid("{42429667-ae04-11d0-a4f8-00aa00a749b9}")
    SipSetCurrentIM(clsidKbdIM.ToByteArray())
    Dim hWnd As IntPtr
    hWnd = FindWindow("SipWndClass", "")
    hWnd = GetWindow(hWnd, GW_CHILD)
    Dim hDC As IntPtr
    hDC = GetDC(hWnd)
    Dim pixel As Integer
    pixel = GetPixel(hDC, 2, 2)
    Dim clrText As Integer
    clrText = ((SystemColors.Window.R) Or _
    (SystemColors.Window.G << 8) Or _
    (SystemColors.Window.B << 16))
    SetPixel(hDC, 2, 2, clrText)
    Dim pixelNew As Integer
    pixelNew = GetPixel(hDC, 2, 2) ' Returns 248
    SetPixel(hDC, 2, 2, pixel)
    If (pixel = pixelNew) Then
    Dim msg As Message = Message.Create(hWnd, WM_LBUTTONDOWN, New IntPtr(1), New IntPtr(&H90009))
    MessageWindow.SendMessage(msg)
    msg = Message.Create(hWnd, WM_LBUTTONUP, New IntPtr(0), New IntPtr(&H90009))
    MessageWindow.SendMessage(msg)
    End If
    ReleaseDC(hWnd, hDC)
    End Sub

    ETA: Here's the dll declarations if needed:

    Declare Function FindWindow Lib "coredll" (ByVal wndClass As String, ByVal caption As String) As IntPtr

    Declare Function GetWindow Lib "coredll" (ByVal hWnd As IntPtr, ByVal nType As Integer) As IntPtr

    Declare Function GetPixel Lib "coredll" (ByVal hdc As IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer) As Integer

    Declare Sub SetPixel Lib "coredll" (ByVal hdc As IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer, ByVal clr As Integer)

    Declare Function GetDC Lib "coredll" (ByVal hWnd As IntPtr) As IntPtr

    Declare Sub ReleaseDC Lib "coredll" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr)

    Declare Function SipSetCurrentIM Lib "coredll" (ByVal clsid As Byte()) As Boolean

    Const WM_LBUTTONDOWN As Integer = &H201
    Const WM_LBUTTONUP As Integer = &H202
    Const GW_CHILD As Integer = 5

    Thanks for taking a look. [:D]

    Flynn

    If we can't corrupt the youth of today, the adults of tomorrow won't be any fun...
  • 01-14-2004 14:38 In reply to

    Re: Switching Input Panel into numeric mode

    VB treats differently conversion from byte to int. This is the case where explicit conversion is required:
    instead of

    clrText = ((SystemColors.Window.R) Or _
    (SystemColors.Window.G << 8) Or _
    (SystemColors.Window.B << 16))

    use

    clrText = ((CInt(SystemColors.Window.R)) Or _
    (CInt(SystemColors.Window.G) << 8) Or _
    (CInt(SystemColors.Window.B) << 16))
  • 01-14-2004 15:31 In reply to

    Re: Switching Input Panel into numeric mode

    Hi, Alex.

    Thanks![8D] That was the missing piece.

    Flynn

    If we can't corrupt the youth of today, the adults of tomorrow won't be any fun...
  • 01-14-2004 16:04 In reply to

    Re: Switching Input Panel into numeric mode

    If anyone is interested, I have posted my VB conversion to:

    http://www.flynnarrowstarr.com/prog/IMSwitchVB.zip

    Thanks again for your help, Alex.

    Flynn

    If we can't corrupt the youth of today, the adults of tomorrow won't be any fun...
  • 01-16-2004 5:21 In reply to

    Re: Switching Input Panel into numeric mode

    Well done guys. I have been on the look out for this functionality for over six months!

    A simple extension to both the C# and VB.NET libraries would be the ability to switch it back to QWERTY mode - simply by changing the following line:-
    If (pixel = pixelNew) Then
    to...
    If (pixel <> pixelNew) Then

    Thanks again.
    Joe
  • 04-27-2004 6:04 In reply to

    Re: Switching Input Panel into numeric mode

    Could any one here please tell me more about this code

    If (pixel = pixelNew) Then
    Dim msg As Message = Message.Create(hWnd, WM_LBUTTONDOWN, New IntPtr(1), New IntPtr(&H90009))
    MessageWindow.SendMessage(msg)
    msg = Message.Create(hWnd, WM_LBUTTONUP, New IntPtr(0), New IntPtr(&H90009))
    MessageWindow.SendMessage(msg)
    End If

    I don't know how to use Message.Create. How can i simulate stylus
    click on "TAB" or "SHIFT" other than "123".

    Thanks in advance
  • 07-13-2004 5:39 In reply to

    Re: Switching Input Panel into numeric mode

    Hi,
    Can somebody help me to get same functionionality in EVB?
    Thanks in anticipation.


    Saeed
  • 11-24-2004 19:24 In reply to

    Re: Switching Input Panel into numeric mode

    If you want the ability to switch between numeric & alpha modes, then take the code within the button click event and move it to a new sub that accepts a boolean parameter (yes if numeric, no if alpha). Then, change the code (VB) to:

    If pNumeric = True Then

    'if the pixel equals the new pixel then call
    'the button click to get the numeric version

    If (pixel = pixelNew) Then

    ' Simulate stylus click
    Dim msg As Message = Message.Create(hWnd, _
    WM_LBUTTONDOWN, New IntPtr(1), New IntPtr(&H90009))
    MessageWindow.SendMessage(msg)
    msg = Message.Create(hWnd, _
    WM_LBUTTONUP, New IntPtr(0), New IntPtr(&H90009))
    MessageWindow.SendMessage(msg)

    End If

    Else 'we want the alpha version

    If (pixel <> pixelNew) Then

    ' Simulate stylus click
    Dim msg As Message = Message.Create(hWnd, _
    WM_LBUTTONDOWN, New IntPtr(1), New IntPtr(&H90009))
    MessageWindow.SendMessage(msg)
    msg = Message.Create(hWnd, _
    WM_LBUTTONUP, New IntPtr(0), New IntPtr(&H90009))
    MessageWindow.SendMessage(msg)

    End If

    End If

    And add a new button that will show the alpha keyboard...


    Thanks everyone so much for this code - it has proven to be a lifesaver! [:D] (sorry for the poor formating)


    Tina
  • 12-28-2004 14:18 In reply to

    Re: Switching Input Panel into numeric mode

    I got an error on PNumeric, how shut the it be declared

    Henrik, Denmark
  • 11-10-2005 4:32 In reply to

    Re: Switching Input Panel into numeric mode

    Has anyone got this code in C# as Alexs website is down.
    http://www.alexfeinman.com/download.asp?doc=IMSwitch.zip


    Thanks
    Serena
  • 04-05-2008 5:55 In reply to

    • palewar
    • Top 100 Contributor
    • Joined on 04-05-2008
    • Nagpur, India
    • Posts 4

    Re: Switching Input Panel into numeric mode

    Any ideas on how the same thing can be done with hardware keyboards instead of virtual keyboards? I have a Treo700 and when I press the key 'R' without pressing option button to switch to numeric mode, I would like '2' to be entered. Have been looking for this for sometime now. If anybody has any suggestions, I will be very greatful.

    Sachin Palewar

    Palewar Techno Solutions
    (Mobile Solutions for Your Business)
    http://www.palewar.com
    http://palewar.blogspot.com

  • 04-08-2008 6:58 In reply to

    • Neil
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-30-2007
    • North Wales
    • Posts 1,092

    Re: Switching Input Panel into numeric mode

    You can use the Microsoft.WindowsCE.Forms.InputModeEditor.SetInputMode method to set the input mode to numeric for the particular textbox you're interested in.

  • 04-09-2008 2:12 In reply to

    • palewar
    • Top 100 Contributor
    • Joined on 04-05-2008
    • Nagpur, India
    • Posts 4

    Re: Switching Input Panel into numeric mode

    Neil I appreciate your response but I don't think I can use inputmodeeditor for a PocketPC. I tried creating a Windows Mobile 5 PocketPC application, I can not use inputmode editor there. Many people have responded me saying I need to use inputmodeeditor. I have tried it many times, so either I am missing something here or inputmodeeditor is not an answer to my problem.

     Again I want to achieve this on Windows Mobile Pocket PCs like Symbol MC35 and Treo 700w, both have hardware keyboards and to complicate the matter both have different keyboard layouts.

     I didn't ever think that such a simple thing is not possible out of the box with windows mobile.

    Neil I have full confidence in you and know that you can help me in this regard so I will appreciate if you can let me know how to use InputModeEditor with PocketPC or if there is any other way to achieve this?
     

    Sachin Palewar

    Palewar Techno Solutions
    (Mobile Solutions for Your Business)
    http://www.palewar.com
    http://palewar.blogspot.com

  • 04-09-2008 2:41 In reply to

    • palewar
    • Top 100 Contributor
    • Joined on 04-05-2008
    • Nagpur, India
    • Posts 4

    Re: Switching Input Panel into numeric mode

    I found 2 relevant discussions at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1761091&SiteID=1  and http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1114869&SiteID=1

    After reading those threads I guess its not possible to change hardware keyboard output to numeric with windows mobile 5 PPC platform. However windows mobile 6 supports that using a pInvoke call. I am disappointed by this.

     Anyway Neil if you can think of any better suggestion for me, then it will be much appreciated. Thanks in advance.
     


     

    Sachin Palewar

    Palewar Techno Solutions
    (Mobile Solutions for Your Business)
    http://www.palewar.com
    http://palewar.blogspot.com

Page 1 of 2 (17 items) 1 2 Next >