Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. "On screen keyboard" user control

"On screen keyboard" user control

Scheduled Pinned Locked Moved C#
tutorialquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alan Zhao
    wrote on last edited by
    #1

    Hi, I am trying to write a custom user control which is a "On screen keyboard" used for touch screen monitor. So when user press a key on the "On screen keyboard", the program knows as if the key on the keyboard is pressed. What should I have in KeyPress event for each keyboard character? or there are some other ways to do it? Also, how to loop through all key chars on keyboard? Thank!!!!

    M 1 Reply Last reply
    0
    • A Alan Zhao

      Hi, I am trying to write a custom user control which is a "On screen keyboard" used for touch screen monitor. So when user press a key on the "On screen keyboard", the program knows as if the key on the keyboard is pressed. What should I have in KeyPress event for each keyboard character? or there are some other ways to do it? Also, how to loop through all key chars on keyboard? Thank!!!!

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      Alan Zhao wrote: What should I have in KeyPress event for each keyboard character? How complete a keyboard are you emulating? Anyways, the truly simple way of figuring this out is try it with a keyboard! However, the right answer (I think) is that you'll want to inject the key-down and key-up messages into the Windows message queue. These keycodes are different (I think) from what you get with KeyPress. The reason for doing it this way is that any control can then receive the key up/down messages from your (I suppose) background thread. It's probably a bit more complicated than I've described, but that's the approach I would start with. Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog

      A H 2 Replies Last reply
      0
      • M Marc Clifton

        Alan Zhao wrote: What should I have in KeyPress event for each keyboard character? How complete a keyboard are you emulating? Anyways, the truly simple way of figuring this out is try it with a keyboard! However, the right answer (I think) is that you'll want to inject the key-down and key-up messages into the Windows message queue. These keycodes are different (I think) from what you get with KeyPress. The reason for doing it this way is that any control can then receive the key up/down messages from your (I suppose) background thread. It's probably a bit more complicated than I've described, but that's the approach I would start with. Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog

        A Offline
        A Offline
        Alan Zhao
        wrote on last edited by
        #3

        How do you send the messages to Windows message queue and what's Windows message queue? I am emulating a keyboard with all letters, digits, and a enter key. Correction: What should I have in MouseDown or Click event b/c the keys are clicked by touch on the screen.

        H 1 Reply Last reply
        0
        • M Marc Clifton

          Alan Zhao wrote: What should I have in KeyPress event for each keyboard character? How complete a keyboard are you emulating? Anyways, the truly simple way of figuring this out is try it with a keyboard! However, the right answer (I think) is that you'll want to inject the key-down and key-up messages into the Windows message queue. These keycodes are different (I think) from what you get with KeyPress. The reason for doing it this way is that any control can then receive the key up/down messages from your (I suppose) background thread. It's probably a bit more complicated than I've described, but that's the approach I would start with. Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Actually, they are the same, fortunately. This saves work of having to define a separate enum to send keyboard messages and P/Invoke related functions. This is true for the .NET FCL as well - it saves them work, too.

          Microsoft MVP, Visual C# My Articles

          A 1 Reply Last reply
          0
          • A Alan Zhao

            How do you send the messages to Windows message queue and what's Windows message queue? I am emulating a keyboard with all letters, digits, and a enter key. Correction: What should I have in MouseDown or Click event b/c the keys are clicked by touch on the screen.

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            The Windows message queue is the heart of the Windows operating system, something you really should understand before attempting such a project. The message queue is just what it (should) sounds like: a queue for messages. A message contains data about the destination window (every control and dialog in Windows is a window), the message you want to send, and to parameters that can point to anything and be used for whatever you like (although the pre-defined Windows messages do define what those should contain in the Platform SDK on MSDN Online[^]. You should read about Windowing[^] to gain a better understanding. You can also P/Invoke SendInput, which is defined and discussed in the function reference section of another section you should read and understand, Keyboard Input[^]. If you're not familiar with P/Invoke, you should learn[^], but you could also just take a look at http://pinvoke.net/default.aspx/user32.SendInput[^].

            Microsoft MVP, Visual C# My Articles

            1 Reply Last reply
            0
            • H Heath Stewart

              Actually, they are the same, fortunately. This saves work of having to define a separate enum to send keyboard messages and P/Invoke related functions. This is true for the .NET FCL as well - it saves them work, too.

              Microsoft MVP, Visual C# My Articles

              A Offline
              A Offline
              Alan Zhao
              wrote on last edited by
              #6

              So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor. Thank!

              H M 2 Replies Last reply
              0
              • A Alan Zhao

                So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor. Thank!

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                I already told you in my other reply to your thread: http://www.codeproject.com/script/comments/forums.asp?msg=830391&forumid=1649#xx830391xx[^].

                Microsoft MVP, Visual C# My Articles

                1 Reply Last reply
                0
                • A Alan Zhao

                  So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor. Thank!

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #8

                  Alan Zhao wrote: So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor. You'll need a worker thread monitoring the input from the touch screen. The one's I've used had an RS-232 interface that provided the x, y coordinates of where the user touched. Of course, this had to be de-jittered, tested for a sufficiently long period of touch, and mapped to whatever graphics I had on the screen. Oh yes, and there's a calibration process involved to. Sounds like you're in some deep water. :) Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog

                  A 1 Reply Last reply
                  0
                  • M Marc Clifton

                    Alan Zhao wrote: So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor. You'll need a worker thread monitoring the input from the touch screen. The one's I've used had an RS-232 interface that provided the x, y coordinates of where the user touched. Of course, this had to be de-jittered, tested for a sufficiently long period of touch, and mapped to whatever graphics I had on the screen. Oh yes, and there's a calibration process involved to. Sounds like you're in some deep water. :) Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog

                    A Offline
                    A Offline
                    Alan Zhao
                    wrote on last edited by
                    #9

                    Hi, thanks for the help, but I didn't expect it to be this complicated.;) This on-screen keyboard is written in Visual C#, so each Button represents a key. Therefore, when the user touch the button on the screen, it's like you click the button using mouse. So the SomeKey_Click() event fired. My problem is how do I tell system that SomeKey is pressed without physically type the key. Thanks again!

                    M 1 Reply Last reply
                    0
                    • A Alan Zhao

                      Hi, thanks for the help, but I didn't expect it to be this complicated.;) This on-screen keyboard is written in Visual C#, so each Button represents a key. Therefore, when the user touch the button on the screen, it's like you click the button using mouse. So the SomeKey_Click() event fired. My problem is how do I tell system that SomeKey is pressed without physically type the key. Thanks again!

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #10

                      I'm a bit confused as to the state of affairs. Alan Zhao wrote: This on-screen keyboard is written in Visual C#, so each Button represents a key. Is that part working already? Alan Zhao wrote: Therefore, when the user touch the button on the screen, it's like you click the button using mouse. Does that part work too? Alan Zhao wrote: So the SomeKey_Click() event fired. And each button on the screen has an event associated with it, so that when the user touches the screen, the button's Click event fires? Alan Zhao wrote: My problem is how do I tell system that SomeKey is pressed without physically type the key. Heath already answered that question, I thought. Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups