Jump to content

Please help with on-screen keyboard and input box entry


Recommended Posts

I need to create an on-screen keyboard to fill values in on a form, the idea is you can enter numerical data in the input boxes and move from input box to input box only by using the mouse. The problem I am having is if you click on the input box then click on the numeric on-screen keypad the cursor is removed from the box and the sent keystroke is missed, I can't seem to find a way around this, I have posted my test form below, hopefully someone will know how to do this or point me in the right direction.

Thanks.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Keypad Test", 679, 397, -1, -1)
GUISetBkColor(0xFFFF00)
$Key1 = GUICtrlCreateButton("1", 392, 200, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Key2 = GUICtrlCreateButton("2", 456, 200, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Key3 = GUICtrlCreateButton("3", 520, 200, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Key4 = GUICtrlCreateButton("4", 392, 144, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Key5 = GUICtrlCreateButton("5", 456, 144, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Key6 = GUICtrlCreateButton("6", 520, 144, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Key7 = GUICtrlCreateButton("7", 392, 88, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Key8 = GUICtrlCreateButton("8", 456, 88, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Key9 = GUICtrlCreateButton("9", 520, 88, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
$Del = GUICtrlCreateButton("Delete", 456, 256, 121, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetTip(-1, "Delete last number.")
GUICtrlSetCursor (-1, 0)
$Label12 = GUICtrlCreateLabel("Value1", 80, 128, 54, 25)
GUICtrlSetFont(-1, 12, 400, 4, "@Arial Unicode MS")
$Barcode5 = GUICtrlCreateInput("", 80, 160, 105, 29)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
$Val5 = GUICtrlCreateInput("", 224, 160, 105, 29)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
$Label13 = GUICtrlCreateLabel("Value 2", 224, 128, 58, 25)
GUICtrlSetFont(-1, 12, 400, 4, "@Arial Unicode MS")
$Key0 = GUICtrlCreateButton("0", 392, 256, 57, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Key0
    Send("0")
Case $Key1
    Send("1")
Case $Key2
    Send("2")
Case $Key3
    Send("3")
Case $Key4
    Send("4")
Case $Key5
    Send("5")
Case $Key6
    Send("6")
Case $Key7
    Send("7")
Case $Key8
    Send("8")
Case $Key9
    Send("9")
Case $Del
    Send("{DEL}")
EndSwitch
WEnd
Edited by Illuma
Link to comment
Share on other sites

  • Moderators

Illuma,

The trick is to find which input last had focus before it was stolen by the keys: :mellow:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$Form1_1 = GUICreate("Keypad Test", 679, 397, -1, -1)
GUISetBkColor(0xFFFF00)

$Key0 = GUICtrlCreateButton("0", 392, 256, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key1 = GUICtrlCreateButton("1", 392, 200, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key2 = GUICtrlCreateButton("2", 456, 200, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key3 = GUICtrlCreateButton("3", 520, 200, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key4 = GUICtrlCreateButton("4", 392, 144, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key5 = GUICtrlCreateButton("5", 456, 144, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key6 = GUICtrlCreateButton("6", 520, 144, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key7 = GUICtrlCreateButton("7", 392, 88, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key8 = GUICtrlCreateButton("8", 456, 88, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Key9 = GUICtrlCreateButton("9", 520, 88, 57, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetCursor(-1, 0)
$Del = GUICtrlCreateButton("Delete", 456, 256, 121, 49)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
GUICtrlSetTip(-1, "Delete last number.")
GUICtrlSetCursor(-1, 0)

$Label12 = GUICtrlCreateLabel("Value1", 80, 128, 54, 25)
GUICtrlSetFont(-1, 12, 400, 4, "@Arial Unicode MS")
$Barcode5 = GUICtrlCreateInput("", 80, 160, 105, 29)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
$hBarcode = GUICtrlGetHandle(-1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Val5 = GUICtrlCreateInput("", 224, 160, 105, 29)
GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
$hVal = GUICtrlGetHandle(-1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Label13 = GUICtrlCreateLabel("Value 2", 224, 128, 58, 25)
GUICtrlSetFont(-1, 12, 400, 4, "@Arial Unicode MS")

GUISetState(@SW_SHOW)

$iFocus = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Key0 To $Del
            ; Get value of key
            $iKeyValue = $nMsg - $Key0
            Switch $iKeyValue
                Case 0 To 9
                    ; Add key value to content
                    GUICtrlSetData($iFocus, GUICtrlRead($iFocus) & $iKeyValue)
                Case 10
                    ; Delete all content
                    GUICtrlSetData($iFocus, "")
            EndSwitch
    EndSwitch

    ; Check which input last had focus
    Switch _WinAPI_GetFocus()
        Case $hBarcode
            $iFocus = $Barcode5
        Case $hVal
            $iFocus = $Val5
    EndSwitch

WEnd

Note that I used GUICtrlGetHandle to get the Windows handle for the 2 inputs - the API call requires this and not the AutoIt ControlID - look for the <<<<<<<<<<<<< lines.

Only use Send to external apps - if the control is in your own GUI, use GUICtrlSetData as in the example. :(

M23

Edit: Added the note about handles/ControlIDs

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Well thanks again Melba23, for the 'last had focus' thing. I knew this was the obstacle to overcome, but wasn't sure how to get it done.. I wanted to make a helpful post the OP, but I didn't want to say 'this is what needs to be done', w/o being able to say 'this is how to do it'.. This will help me with another project I have on the back burner. Seems I'm cookin' with gas again!

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

  • Moderators

snowmaker,

Glad I could help without even knowing it! :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks allot Melba23 that was spot on! I have now added your method to main program and it works great.

Thanks again!

It'salso worth looking at Wraithdu's solution which has on on-screen keyboard which doesn't steal the focus from other windows.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

martin,

I was going to recommend the same thing until I realised that the OP was only trying to set the contents of inputs in his own GUI. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

It'salso worth looking at Wraithdu's solution which has on on-screen keyboard which doesn't steal the focus from other windows.

Hi Martin

The keyboard thing is sorted now, but I just wanted to thank you for your serial port UDF, I have used it a few times to communicate with thermal printers and TV,s it's great and always worked fine. So thank you to you sir, you have saved me allot of head scratching!

Link to comment
Share on other sites

Hi Martin

The keyboard thing is sorted now, but I just wanted to thank you for your serial port UDF, I have used it a few times to communicate with thermal printers and TV,s it's great and always worked fine. So thank you to you sir, you have saved me allot of head scratching!

Well thank you Illuma for taking the trouble to say that. I'm very pleased the UDF has helped you.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 8 years later...

@Melba23

Know this topic is ancient but I am implementing the same thing and am having issues with it trying to set the value into an IP Control with the following. My issue is that it doesn't seem to be updating the control and outputting to the console doesn't seem to be reading the value correctly. (Only getting the single value "0.0.0.1") so it looks like it's never setting the value.

 

Any help understanding why would be great. I may just end up turning this into a normal input and adding a "." to the virtual number pad.

$I_IPAddress = _GUICtrlIpAddress_Create($Form1_1, 37, 43, 130, 21)
    _GUICtrlIpAddress_Set($I_IPAddress, "10.0.0.0")
    $H_I_IPAddress = GUICtrlGetHandle(-1)
    
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Key0 To $Del
            ; Get value of key
            $iKeyValue = $nMsg - $Key0
            Switch $iKeyValue
                Case 0 To 9
                    ; Add key value to content
                    ConsoleWrite(_GUICtrlIpAddress_Get($iFocus) & $iKeyValue)
                    _GUICtrlIpAddress_Set($iFocus, _GUICtrlIpAddress_Get($iFocus) & $iKeyValue)
                Case 10
                    ; Delete all content
                    GUICtrlSetData($iFocus, "")
            EndSwitch
    EndSwitch

    ; Check which input last had focus
    Switch _WinAPI_GetFocus()
        Case $H_I_IPAddress
            $iFocus = $I_IPAddress
    EndSwitch

 

Link to comment
Share on other sites

The original issue still stands with the IPAddress_ control but I have found another solution for now by just creating another button (".") and adding it to the Switch...Case. Changes can be found below for anyone else that may stumble across this like I did. Still curious about the IPAddress_ control issue though if anyone has an idea on what is wrong.

 

$G_OnscreenKeyboard = GUICtrlCreateGroup("Onscreen Keyboard", 208, 8, 217, 249)
    $Key0 = GUICtrlCreateButton("0", 224, 197, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key1 = GUICtrlCreateButton("1", 224, 141, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key2 = GUICtrlCreateButton("2", 288, 141, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key3 = GUICtrlCreateButton("3", 352, 141, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key4 = GUICtrlCreateButton("4", 224, 85, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key5 = GUICtrlCreateButton("5", 288, 85, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key6 = GUICtrlCreateButton("6", 352, 85, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key7 = GUICtrlCreateButton("7", 224, 29, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key8 = GUICtrlCreateButton("8", 288, 29, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Key9 = GUICtrlCreateButton("9", 352, 29, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $KeyDot = GUICtrlCreateButton(".", 288, 197, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetCursor (-1, 0)
    $Del = GUICtrlCreateButton("Delete", 352, 197, 57, 49)
    GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS")
    GUICtrlSetTip(-1, "Delete last number.")
    GUICtrlSetCursor (-1, 0)   
           
           Switch $iKeyValue
                Case 0 To 9
                    ; Add key value to content
                    GUICtrlSetData($iFocus, GUICtrlRead($iFocus) & $iKeyValue)
                Case 10
                    ; Add dot
                    GUICtrlSetData($iFocus, GUICtrlRead($iFocus) & ".")
                Case 11
                    ;Delete all content
                    ConsoleWrite("Pressed")
                    GUICtrlSetData($iFocus, "")

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...