Illuma Posted March 8, 2010 Share Posted March 8, 2010 (edited) 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.expandcollapse popup#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 March 8, 2010 by Illuma Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 8, 2010 Moderators Share Posted March 8, 2010 (edited) Illuma,The trick is to find which input last had focus before it was stolen by the keys: expandcollapse popup#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 WEndNote 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. M23Edit: Added the note about handles/ControlIDs Edited March 8, 2010 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
somdcomputerguy Posted March 8, 2010 Share Posted March 8, 2010 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 More sharing options...
Moderators Melba23 Posted March 8, 2010 Moderators Share Posted March 8, 2010 snowmaker, Glad I could help without even knowing it! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Illuma Posted March 8, 2010 Author Share Posted March 8, 2010 Thanks allot Melba23 that was spot on! I have now added your method to main program and it works great. Thanks again! Link to comment Share on other sites More sharing options...
martin Posted March 8, 2010 Share Posted March 8, 2010 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 More sharing options...
Moderators Melba23 Posted March 8, 2010 Moderators Share Posted March 8, 2010 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Illuma Posted March 8, 2010 Author Share Posted March 8, 2010 It'salso worth looking at Wraithdu's solution which has on on-screen keyboard which doesn't steal the focus from other windows.Hi MartinThe 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 More sharing options...
martin Posted March 8, 2010 Share Posted March 8, 2010 Hi MartinThe 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 More sharing options...
xCROv Posted May 17, 2018 Share Posted May 17, 2018 @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 More sharing options...
xCROv Posted May 17, 2018 Share Posted May 17, 2018 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. expandcollapse popup$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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now