Jump to content

Help with simple key inserter


Recommended Posts

Hi, this is my 1st project in a LONG time.

I'm wanting to create an on screen keypad with buttons which when pressed, will send a simple key entry to the program below.

I've started to create it after watching a couple of YouTube videos but when I have compiled and tested it, it's not worked.

1st problem. I'm not sure how to keep my gui on top.

If I click the program (lets say notepad) it will fall behind.

2. The buttons don't seem to work.

So far, I've managed to create the gui, but if I press one of the buttons, I get a strange noise from my speakers until I either press a button I've not defined or click out of the gui. It also doesn't write the text I wanted it to in notepad.

 

Here's an example of one of the buttons...

Global $priceoverride = GUICtrlCreateButton ("Price Override", 16, 128, 75, 49)

 

While 1

$nMsg = GUIGetMSG (D

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $priceoverride

Send ("p{enter}")

 

I was expecting p followed by the enter key to be entered onto the program below but it doesn't.

If someone can explain what I'm doing wrong and how to do it correctly, I would be very grateful.

I'm thinking it might be because I didn't add it into a function but, I've no idea, hence why I am asking.

 

Kind Regards,

Chiller.

 

 

Link to comment
Share on other sites

  • Developers

It will send the P+Enter to the active window which likely is your own GUI.
What exactly are you trying to automate?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Have you checked whether this POS program has proper Control information with au3info to figure out whether you can use Controlxxxx functions?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I'm not sure if it does or not, I don't have a copy of the program to hand and I doubt they would allow me to analyse it in fear of a security breach. The tool I'm working on, I'm doing off my own back in order to gain recognition within the company. I've made managers aware of my ideas and they agree that it would be very beneficial to them however, HR are currently unaware of anything until I can create a working demo / beta.

Link to comment
Share on other sites

  • Developers

au3info only checks the GUI information and there is no option for security breaches. I would rather think that you wouldn't be allowed to run any "unknown" program on a POS, so am surprised you can run AutoIt3 scripts on it.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

From what  my manager has said, if I can show him something which works (not sure if he means to install it on the POS system or not) he will get in contact with his bosses and the IT department to make it happen.

My idea would be for now at least to make an app which is capable of:

1. staying on top
2. sending the text strings to the next app down (regardless if it was notepad, word or the POS) just as a proof of concept.

Link to comment
Share on other sites

  • Developers

That's pretty "simple". Just open the helpfile on the Controlxxxx functions and have a play. These Controlxxx functions don't require the target window to have the focus as you send the message (information) to the GUI & explicit Control.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi again, so I've decided to point my script to notepad for now just to show that I have a working concept as I couldn't find a control string which would work in a similar way to an on screen keyboard.

I tested it out but it returns an error: 

Quote

Line 933 C:\xxx.exe Error: Incorrect number of parameters in function call.

this has left me confused as I read the help file.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIResizeMode", $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
Opt("GUIResizeMode", $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
#Region ### START Koda GUI section ### Form=c:\documents and settings\jess\my documents\downloads\koda_1.7.3.0\forms\prontokeys.kxf
Global $ProntoKeys = GUICreate("PKeys", 251, 338, 188, 112)
Global $ProntoKeys = GUICtrlCreateGroup("ProntoKeys", 8, 16, 233, 313)
Global $priceovrde = GUICtrlCreateButton("Price Override", 16, 128, 75, 49)
Global $suspend = GUICtrlCreateButton("Suspend", 88, 128, 75, 49)
Global $susres = GUICtrlCreateButton("Suspend Res", 160, 128, 75, 49)
Global $layby = GUICtrlCreateButton("Layby", 16, 176, 75, 49)
Global $laybyres = GUICtrlCreateButton("Layby Resume", 88, 176, 75, 49)
Global $laybyhold = GUICtrlCreateButton("Layby Hold", 160, 176, 75, 49)
Global $stockenq = GUICtrlCreateButton("Stock Enquiry", 16, 224, 75, 49)
Global $branch = GUICtrlCreateButton("Branch", 88, 224, 75, 49)
Global $backorder = GUICtrlCreateButton("Back Order", 160, 224, 75, 49)
Global $ttl = GUICtrlCreateButton("Tender Type", 16, 272, 75, 49)
Global $cussearch = GUICtrlCreateButton("Customer Enq", 88, 272, 75, 49)
Global $mm = GUICtrlCreateButton("Main Menu", 160, 272, 75, 49)
Global $card = GUICtrlCreateButton("Card Payment", 16, 32, 75, 49)
Global $Cash = GUICtrlCreateButton("Cash", 88, 32, 75, 49)
Global $Subtotal = GUICtrlCreateButton("Subtotal", 160, 32, 75, 49)
Global $linevoid = GUICtrlCreateButton("Line Void", 16, 80, 75, 49)
Global $cnclorder = GUICtrlCreateButton("Cancel Order", 88, 80, 75, 49)
Global $Refund = GUICtrlCreateButton("Refund", 160, 80, 75, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

         Case $Subtotal
            ControlSend("Untitled - Notepad", "", "st{enter}")
         Case $susres
            ControlSend("Untitled - Notepad", "", "res{enter}")
         Case $card
            ControlSend("Untitled - Notepad", "", "up{enter}")
         Case $Cash
            ControlSend("Untitled - Notepad", "", "at{enter}")
         Case $mm
            ControlSend("Untitled - Notepad", "", "posretm{enter}")
         Case $priceovrde
            ControlSend("Untitled - Notepad", "", "p{enter}")
         Case $Refund
            ControlSend("Untitled - Notepad", "", "acr{enter}")
         Case $linevoid
            ControlSend("Untitled - Notepad", "", "v{enter}")
         Case $cnclorder
            ControlSend("Untitled - Notepad", "", "va{enter}")
         Case $layby
            ControlSend("Untitled - Notepad", "", "acl{enter}")
         Case $laybyres
            ControlSend("Untitled - Notepad", "", "reslayby{enter}")
         Case $laybyhold
            ControlSend("Untitled - Notepad", "", "lbyhold{enter}")
         Case $backorder
            ControlSend("Untitled - Notepad", "", "bo{enter}")
         Case $suspend
            ControlSend("Untitled - Notepad", "", "sus{enter}")
         Case $cussearch
            ControlSend("Untitled - Notepad", "", "zcrm{enter}")
         Case $mm
            ControlSend("Untitled - Notepad", "", "posretb{enter}")
         Case $ttl
            ControlSend("Untitled - Notepad", "", "tt{enter}")
         Case $branch
            ControlSend("Untitled - Notepad", "", "b{enter}")
EndSwitch
 WEnd

I hope you can find what I did wrong.

Kind regards,

Chiller.

Link to comment
Share on other sites

  • Developers

Install the full SciTE4AutoIt3 version (see my sig). This will make your life easier and in this case would run au3check telling you this:

test.au3"(38,62) : error: ControlSend() [built-in] called with wrong number of args.
            ControlSend("Untitled - Notepad", "", "st{enter}")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

.. and when you check the helpfile you see that it requires 4 parameters, not 3 as you have. :)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

You are sure you opened the helpfile on ControlSend() as the example for the function contains an example for notepad?
 (hit F1 when you caret is in the word somewhere) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Got it, I missed where AutoIt should be pointing the text to within notepad. 

Is there no way to point script to direct key entry like an on screen keyboard would?

I'm guessing, you would somehow have to tell it to ignore the AutoIt window and point the script / text to the next window down?

Also, is there currently a way to keep the AutoIt window on top?

Link to comment
Share on other sites

  • Developers
1 minute ago, chillerhippie said:

Is there no way to point script to direct key entry like an on screen keyboard would?

Not sure what you are asking here. Can you elaborate?

2 minutes ago, chillerhippie said:

Also, is there currently a way to keep the AutoIt window on top?

Do you mean your own GUI of the AutoIt3 script? If so, Yes you can: $WS_EX_TOPMOST for exstyle on GuiCreate.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

10 minutes ago, Jos said:

Not sure what you are asking here. Can you elaborate?

If you use an on screen keyboard for example:
https://support.microsoft.com/en-gb/help/10762/windows-use-on-screen-keyboard

The keyboard will stay on top and regardless if you're in word, notepad, a website or even a game, the key presses are replicated from the on screen keyboard into whatever application you are using.

is there a way to replicate that sort of behavior when creating a GUI?

Link to comment
Share on other sites

  • Developers
Just now, chillerhippie said:

is there a way to replicate that sort of behavior when creating a GUI?

Didn't I answer that in the second part of my last post?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You gave me the answer for Always on top behavior (thank you for that)

The one I'm on about would be where the keyboard doesn't require pointing to the location you want the text string to be input. My guess would be, the user launches the text editor or website and if necessary, clicks on where they want to enter the text then types on the on screen keyboard which inputs what ever the user writes into the last / open text box.

Either that or the on screen keyboard is programed to replicate key presses at the same time as floating above all other apps without actually been the selected app?

I'm not sure on how they actually work, merely speculating how I think they may overcome the virtual key presses been pointed to itself.

Link to comment
Share on other sites

  • Moderators

chillerhippie,

How about this virtual keyboard script from my snippets folder:

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

$MA_NOACTIVATE = 3
$MA_NOACTIVATEANDEAT = 4

HotKeySet("{ESC}", "On_Exit")

Global $aKeys[48] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", _
                     "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", _
                     "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", '"', _
                     "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "spc", "enter"]

; Create "keyboard" GUI
$hGUI = GUICreate("Test", 360, 120, 500, 100, $WS_POPUPWINDOW, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE))

$cStart = GUICtrlCreateDummy() + 1
$iCount = 0
For $j = 0 To 3
    For $i = 0 To 11
        GUICtrlCreateButton($aKeys[$iCount], $i * 30, $j * 30, 30, 30)
        $iCount += 1
    Next
Next
$cEnd = GUICtrlCreateDummy() - 1

GUISetState()

GUIRegisterMsg($WM_MOUSEACTIVATE, "_WM_MOUSEACTIVATE")

Run("notepad.exe")

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cStart To $cEnd
            Local $sText = ControlGetText($hGUI, "", $iMsg)
            ; Write key
            If $sText = "spc" Then
                Send("{SPACE}")
            ElseIf $sText = "enter" Then
                Send("{ENTER}")
            Else
                Send($sText)
            EndIf
    EndSwitch
WEnd

Func _WM_MOUSEACTIVATE($hWndGUI, $iMsg, $WParam, $LParam)
    Switch $hWndGUI
        Case $hGUI
            Switch $iMsg
                Case $WM_MOUSEACTIVATE
                    ; Check mouse position
                    Local $aMouse_Pos = GUIGetCursorInfo($hGUI)
                    If $aMouse_Pos[4] <> 0 Then
                        _SendMessage($hGUI, $WM_COMMAND, _WinAPI_MakeLong($aMouse_Pos[4], $BN_CLICKED), GUICtrlGetHandle($aMouse_Pos[4]))
                    EndIf
                    Return $MA_NOACTIVATEANDEAT
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func On_Exit()
    Exit
EndFunc

I believe it was wraithdu who produced this version, although a number of us worked together to get there.

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

  • Moderators

kylomas,

As I recall, that was wraithdu's critical addition to the code - so best ask him.

M23

Edit: Found the original thread.

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

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