Jump to content

String Sender GUI: Is There a Better Way?


Recommended Posts

Hello Everyone. I'm trying to create a GUI-based script that holds several text strings entered by the user. The idea is to place the mouse cursor at the insertion point in some app and then press a "hot key" to send a text string there. The script that I have written seems to work, but it is flakey. Any suggestions would be greatly appreciated.stringsender.au3stringsender.au3stringsender.au3stringsender.au3stringsender.au3stringsender.au3stringsender.au3stringsender.au3stringsender.au3

Edited by wiretwister
Link to comment
Share on other sites

It works but sometimes it might not send the string because of the SendKeyDelay. And what on earth is this suppose to do?

While 1
    $event = GUIGetMsg()
    Switch $event
        Case $GUI_EVENT_CLOSE
            Exit
        String1
        String2
        String3
        String4
        String5
    EndSwitch
WEnd

 

When the words fail... music speaks.

Link to comment
Share on other sites

Thank you for responding.
I don't think the problem involves SendKeyDelay. The script behavior is erratic with or without this. The part of the script that you show in your reply is the loop that processes User input (GUI MessageLoop Mode). As far as I can tell, it seems to respond as intended to Alt-1, Alt-2, Alt-3, Alt-4, Alt-5 and CLOSE keyboard inputs. It might be poorly written, but it's a basic part of a GUI script. 

 

Link to comment
Share on other sites

When you post code, please use the method shown in the link.

1 hour ago, wiretwister said:

The script behavior is erratic

What do you mean by erratic ?  Could you make a gif that shows it ?  Or describe in more details the faulty behavior.

ps. I agree that the SendKeyDelay is way too high.  Probably something is interrupting or disturbing the Send.  You could use my UDF to block input while the send is running (see my signature for it).

pps. another thing, using alt+x may also cause problems.  Alt is often use to start/show menu in many applications.  You may want to change your hot keys to something else.

ppps.  Here to get you started with a more robust version :

#include <Misc.au3>
#include <GUIConstants.au3>
#include "C:\Apps\AutoIt\BlockInput\BlockInputUDF.au3"

HotKeySet("^1", SendString)
HotKeySet("^2", SendString)
HotKeySet("^3", SendString)
HotKeySet("^4", SendString)
HotKeySet("^5", SendString)

Local $Form1_1 = GUICreate("String Sender", 910, 314, 286, 349)
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xE3E3E3)
GUICtrlCreateLabel("Usage: Type in or Paste in a text string into each text box. Position the mouse cursor at the location where the text string is to be inserted. Press the hot-key next to the text box to insert the text string.", 8, 0, 893, 49)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUISetBkColor(0xE3E3E3)
GUICtrlCreateLabel("Ctrl 1", 816, 72, 72, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUISetBkColor(0xE3E3E3)
GUICtrlCreateLabel("Ctrl 2", 816, 120, 72, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUISetBkColor(0xE3E3E3)
GUICtrlCreateLabel("Ctrl 3", 816, 168, 72, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUISetBkColor(0xE3E3E3)
GUICtrlCreateLabel("Ctrl 4", 816, 216, 72, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUISetBkColor(0xE3E3E3)
GUICtrlCreateLabel("Ctrl 5", 816, 264, 72, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUISetBkColor(0xE3E3E3)
GUICtrlSetCursor(-1, 2)
Local $Input1 = GUICtrlCreateInput("", 8, 72, 800, 28, -1, -1)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Local $Input2 = GUICtrlCreateInput("", 8, 120, 800, 28, -1, -1)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Local $Input3 = GUICtrlCreateInput("", 8, 168, 800, 28, -1, -1)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Local $Input4 = GUICtrlCreateInput("", 8, 216, 800, 28, -1, -1)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Local $Input5 = GUICtrlCreateInput("", 8, 264, 800, 28, -1, -1)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState()

While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
WEnd

Func SendString()
  While _IsPressed("11")
    Sleep(50)
  WEnd
  _BlockInput($BI_DISABLE)
  ControlSend("", "", "", GUICtrlRead(Eval("Input" & StringRight(@HotKeyPressed, 1))))
  _BlockInput($BI_ENABLE)
EndFunc   ;==>SendString

 

Edited by Nine
Link to comment
Share on other sites

Thanks for taking the time to look at this, Nine...
While fiddling around with it, I also discovered that replacing Send with ControlSend("", "", "",... solved nearly all of the mal-functions.
And your creation of SendString(), with the use of _IsPressed and _BlockInput is a very good way to keep the user from inadvertently making the script send strings to itself.
Your suggestion of using Ctrl instead of Alt for hotkeys makes sense. Less chance of interfering with other apps. I would have preferred single keys, but I was concerned about using Fx keys for this purpose.

I now consider the task to be finished.

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