PDA

Click to See Complete Forum and Search --> : Virtual keyboard


Mad Compie
Feb 20th, 2001, 01:46 PM
Well hi,

I'm working on a virtual keyboard application which works pretty well by now, but I'm looking for an other method to accomplish it.
My app always stays on top and scans the system for any open window using GetWindowFromPoint() during the timer event of a simple Timer Control in my app.
The app contains many buttons, each of them is used as a keyboard button (like A,B,Return, Delete, ...).
When the user presses a button, it's value is transferred to the Window obtained in the timer control. Herefore I'm using the SendMessage API with the WM_CHAR message.
This works, but my goal is to transfer the keypresses ONLY to the window that had the last focus before the keypress event instead of using the GetWindowFromPoint. This could be any window (TextBox, ListBox) of any running application.
The GetFocus API only works for windows, contained in my project, not for other processes.
So, my question: how to obtain which editable object had the last focus...
Hoping for some reactions...

Lord Orwell
Feb 21st, 2001, 12:41 AM
If you used the keypress_event api call, it would behave exactly like you are typing on the keyboard. Keypresses go to active windows, etc.Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)


Parameter Type/Description
bVk Byte—The virtual key code to simulate.
bScan Byte—The OEM scan code for the key.
dwFlags Long—Zero, or one of the two following flags:
KEYEVENTF_EXTENDEDKEY—Indicates that the key is an extended key and prefixed by the 0xE0 code.
KEYEVENTF_KEYUP—Simulates a key release.
dwExtraInfo Long—A value that is typically unused. The GetMessageExtraInfo API can retrieve this value. Allowed values depend on the driver.

Mad Compie
Feb 21st, 2001, 01:53 PM
Thanks for responding, Lord Orwell.
I also use this API to to simulate some function keys like Delete, Home, End, Left, Right, ....
I could also use it for the alphabet keys (but only the uppercase ones) and the numerical keys 0..9.
I use the WM_CHAR message because like this I can also send lowercase keystrokes to the recipient window or other keys like ", $, !, ... which are not supported with the keyb_event API, not?
The problem with WM_CHAR is that it won't do anything with some windows (like MS Word, Outlook Express, ...).
So, how can I simulate these special keystrokes to the recipient using keyb_event?

Lord Orwell
Feb 21st, 2001, 08:45 PM
It would be obvious if you understood one thing:
You need to call the keybd_event function to press a key down, and it stays down until you call it again to release it with a KEYEVENTF_KEYUP. Now that you know how to simulate the up and down position of any key on the keyboard (the alt key is the WM_MENU), i don't forsee you having any problem using upper and lower-case letters, etc.

Mad Compie
Feb 22nd, 2001, 02:05 PM
Yes yes mylord, I call it twice to simulate the keypress, but how can I send characters like !, ", #, q, c, ..., because every attached keyboard could be different, and our touchscreens don't have any keyboard at all!

Example:


keybd_event 65, 0, 0, 0 ' press A
keybd_event 65, 0, KEYEVENTF_KEYUP, 0 ' release A


But how can I use lowercase 'A' ???
If I use it's ASCII equivalent 97 the result is '1'...

Lord Orwell
Feb 23rd, 2001, 05:58 PM
Ok, I seem to have had way too many Fs in that last code post. :rolleyes: Here is WORKING code, that i have thoroughly tested (for a change :D)
Public Sub TypeKey(ByVal c$)
Dim vk%
Dim scan%
Dim oemchar$
Dim dl&
Dim ShiftState As Integer
Dim ss As Long
Dim CtrlState As Integer
Dim AltState As Integer
Dim AllStates As Integer
Dim ShiftScanCode As Integer
Dim CtrlScanCode As Integer
Dim AltScanCode As Integer
ShiftScanCode = MapVirtualKey(vbKeyShift, 0)
CtrlScanCode = MapVirtualKey(vbKeyControl, 0)
AltScanCode = MapVirtualKey(vbKeyMenu, 0)
'ss = (VkKeyScan(Asc(c$)) And &H100) / &HFF
' MsgBox ss
' Get the virtual key code for this character
vk% = VkKeyScan(Asc(c$)) And &HFF
AllStates = (VkKeyScan(Asc(c$)) And &H100) / &HFF
ShiftState = AllStates And 1
CtrlState = (AllStates And 2) / 2
AltState = (AllStates And 4) / 4
oemchar$ = " " ' 2 character buffer
' Get the OEM character - preinitialize the buffer
CharToOem left$(c$, 1), oemchar$
' Get the scan code for this key
scan% = OemKeyScan(Asc(oemchar$)) And &HFF
If ShiftState = 1 Then
keybd_event vbKeyShift, ShiftScanCode, 0, 0
DoEvents
End If
If CtrlState = 1 Then
keybd_event vbKeyControl, CtrlScanCode, 0, 0
DoEvents
End If
If AltState = 1 Then
keybd_event vbKeyMenu, AltScanCode, 0, 0
DoEvents
End If
' Send the key down
keybd_event vk%, scan%, 0, 0
DoEvents
' Send the key up
keybd_event vk%, scan%, KEYEVENTF_KEYUP, 0
DoEvents
If ShiftState = 1 Then
keybd_event vbKeyShift, ShiftScanCode, KEYEVENTF_KEYUP, 0
DoEvents
End If
If CtrlState = 1 Then
keybd_event vbKeyControl, CtrlScanCode, KEYEVENTF_KEYUP, 0
DoEvents
End If
If AltState = 1 Then
keybd_event vbKeyMenu, AltScanCode, KEYEVENTF_KEYUP, 0
DoEvents
End If

End Sub

Mad Compie
Feb 24th, 2001, 07:46 AM
That's great code, Orwell!
Meanwhile I also found some API on Microsoft's PSDK like VkKeyScan(). But now, by having your API's like OemKeyScan() I think that my problem could be solved.
The PSDK also prefers the use of SendInput instead of keyb_event en mouse_event (only Win98 & 2K/NT).
Thank u veru much for responding, Orwell. You've been a great help here...

ATProgrammer
Mar 8th, 2001, 05:29 PM
About virtual keyboard:

I'v got it to work 99% with keybd_event but always when I touch some of the virtual keyboard keys, virtual keyboard gets focus. Usually this is not a problem because I can set the focus back to the "target" window with SetForegroundWindow but f.ex. with Internet Explorer and address combobox it's a problem. When it gets back it focus, address (the first letter I managed to send there with virtual keyboard) gets ALWAYS overwritten. Same features also happens with menus, For example saving document in word is done by pressing ALT + F (down + Up) and then S (sending S). When pressing S on virtual keyboard it gets focus back and menu is loosed and S is written to the text area. How to get around this.

TIA

Lord Orwell
Mar 8th, 2001, 06:46 PM
Could you email me the code sample? I would like to take a look at it.
One way i can think of is to have a text entry area on your keyboard emulator, and after you enter all necessary text, Then set the new focus and send it all.
I did a little experimenting with the code myself that i posted. I have attached a module with a function that nearly replaces the sendkeys function. I am sure by looking at the notes, it will become apparent what needs to be done to add more functionality if what you want is missing. Basically, i just haven't added all of the constants for cursoring around, etc.

Lord Orwell
Mar 8th, 2001, 06:50 PM
Have you tried not releasing the alt until after pressing the s?
Anyway, you stated some time earlier that your program would be used on some systems without keyboards?
I hope this doesnt catch you off guard and you already know this:
If you check your windows accessibility options(the wheelchair), you will see an option for a keyboard emulator for those people who dont have fingers and type with a stylus or something. It is called "on screen keyboard", and has various settings to emulate up to a 106 key keyboard. If you install it, it is placed under "accessories"

Mad Compie
Mar 9th, 2001, 01:39 PM
Yes, but I think it's only for Windows ME (and perhaps Win 2K).
My program works fine now and I don't have this phenomenon of overwriting characters.
I also use the SetForeGroundWindow() API to put the focus back to the window, obtained with GetForeGroundWindow(). This last API is called in a timer routine of my app, which searches every 100ms for the topmost window.

ATProgrammer
Mar 9th, 2001, 05:37 PM
Hi Mad Compie,

Can you launch File menu with your virtual keyboard first by clicking Alt then F and then browse on pull-down menu with cursor down. When I click Alt + F file menu is launched but when I then click cursor down (on virtual keyboard) virtual keyboard gets focus and Alt + F pull-down menu gones a way.

What about Internet explorer address combobox (internet explorer 5) if you first click the address with mouse and then click http://www from your virtual keyboard, does it read http://www in the address combobox or plain w

Mad Compie
Mar 10th, 2001, 06:54 AM
My app doesn't implement the Alt key, but I'll give it a try (after the week-end).
The http://www is also not implemented. But the typing of chars into this box works fine. I'll test it also out. Please wait.

Sastraxi
Mar 10th, 2001, 03:28 PM
What I'd like to know is how you plan on programming on a touch-screen...

Lord Orwell
Mar 11th, 2001, 02:27 AM
I was wondering why he was editing documents on a touch-screen.

Programming FOR one is easy. It emulates a mouse.

Mad Compie
Mar 11th, 2001, 04:50 AM
Hoho guys.
We created a domotics system (using microcontroller Motorola HC16) a few years ago.
Nowadays, with the Pentium processors, it's possible to connect an embedded computer to our system. A Pentium 177 MHz is now fast enough to perform graphical FX.
The idea was to connect such an embedded computer to our system, so one could perform also all tasks using this computer and his serial port.
The embedded computer is composed of a single board Pentium 177Mhz containing: 6 COM ports (where 1 port could be RS/485), 1 parallel port, 1 compact flash connection, 1 disk-on-a-chip connection, a 10/100 Ethernet on-board, an embedded 16bit soundcard, 2x USB slots, connections for PC/104, RAM, keyboard, floppy and IDE and last but not least: an embedded LCD display (SVGA, 15") using ELOtouch touchscreen interface.
The whole thing is faster than a normal Pentium177 and is remarkably small and thin, so it could be easily implemented in a wall or something like that.
I took a Compact Flash disk of 178MB and installed Win95 (with FontSmoothing) into it.
The whole thing runs fast, and it makes NO noise (no cooling needed, the CFD also makes no noise).
The user has no keyboard if it's implemented in a wall, but he should be able to edit some texts of domotics commands. He should also be able to compose an E-mail message.
Result: he needs a virtual keyboard!!!

Please take a look at the following site:
http://www.zflinux.com

and find: NetDisplay 5MX

It's not very expensive too!!!

Lord Orwell
Mar 11th, 2001, 05:07 AM
The program that comes with windows isn't made by windows. Check this out:
http://www.madenta.com/sd2k/

ATProgrammer
Mar 11th, 2001, 06:28 AM
I need a virtual keyboard for 1) Touch-screen POS and 2) Internet kiosk, don't want to use $395 OSK but own $0 system for maximum usablity and profit.

Mad Compie
Mar 11th, 2001, 07:11 AM
Sorry, I developed this virtual keyboard at work to support our domotics system. My boss won't like it very much if I put the code on the net.
But it's not very difficult to create your own VK. I wrote it in just 1 day.
Besides, this thread contains a lot of information to build your custom VK.
Take also a look at Lord Orwell's code and the used API.