Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an localized on-screen-keyboard

I have to write an on screen keyboard for our company's program, which is mostly used on industry's PCs with touch capability.

We can't use the windows default keyboard because we don't need all keys on the keyboard. So I was asked to write a custom one in C#.

I already found this blog as reference, but I'm not sure how to start.

I created a small prototype GUI and assign for each key a scancode, and translate these scancodes to the related character. And send them to the active control. But I'm not sure what scancodes I should use.

So my question is, is that the correct way to write a OSK like this and if yes which scancodes should I use? Any links?

I'm also not sure how to handle the shift states...

Edit:

Okay I did a bit more research and came up with a osk which reads the current keyboard layout and even handles the easy shift states (Shift and Alt Gr). I wrote a KeyButton class which inherits from Button, this KeyButton has a ScanCode property of type byte and if you assign a valid scancode to it, the KeyButton will call the related functions to get the correct text. I used the functions from Michael Kaplan blogs with some small changes. In the end it turned out that I just had to do the same as he did.

So the answer to my question is: Yes, you have to use scancodes on your buttons and then get the virtualkey and the unicode from the keyboard layout. Use these scancodes.

Now I get the characters the only thing left is to send these around.

like image 775
MBulli Avatar asked Nov 05 '22 03:11

MBulli


1 Answers

I think this is fairly simple, just make a series of buttons and assign each button a letter, and inside the buttons Click method you can do a simple.

SendKeys.Send("A"); 

Changing key based on button etc

like image 54
kyndigs Avatar answered Nov 09 '22 12:11

kyndigs