Results 1 to 19 of 19

Thread: Virtual keyboard

  1. #1

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Wink

    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...

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  3. #3

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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?

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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:

    Code:
    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'...

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    Ok, I seem to have had way too many Fs in that last code post. Here is WORKING code, that i have thoroughly tested (for a change )
    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
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  7. #7

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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...

  8. #8
    New Member
    Join Date
    Mar 2001
    Location
    Finland
    Posts
    4

    Question keybd_event and loosed focus

    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
    Programmer

  9. #9
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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.
    Attached Files Attached Files
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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"
    Last edited by Lord Orwell; Mar 8th, 2001 at 08:01 PM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  11. #11

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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.

  12. #12
    New Member
    Join Date
    Mar 2001
    Location
    Finland
    Posts
    4

    Question Yours work, mine don't?

    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
    Programmer

  13. #13

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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.

  14. #14
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    What I'd like to know is how you plan on programming on a touch-screen...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  15. #15
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    I was wondering why he was editing documents on a touch-screen.

    Programming FOR one is easy. It emulates a mouse.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  16. #16

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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!!!

  17. #17
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    The program that comes with windows isn't made by windows. Check this out:
    http://www.madenta.com/sd2k/
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  18. #18
    New Member
    Join Date
    Mar 2001
    Location
    Finland
    Posts
    4

    Wink Why virtual keyboard?

    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.
    Programmer

  19. #19

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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.

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