wiretwister Posted April 16 Posted April 16 (edited) 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 April 16 by wiretwister
Andreik Posted April 16 Posted April 16 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
wiretwister Posted April 17 Author Posted April 17 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.
Nine Posted April 17 Posted April 17 (edited) 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 : expandcollapse popup#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 April 17 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
wiretwister Posted April 18 Author Posted April 18 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.
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