Auto-it Text Expansion / Replacement Gui + source code


Recommended Posts

I know a similar program Texter exists which is much easier to work with but caused problems with other programs in a lot of machines I worked with. So I wrote a GUI for a script which was on the auto-it forum (Credit to the authors, Manadar and Garry Frost). The unaltered source code is available from here.

This takes a little bit of tweaking around to get it to work properly, especially with the file paths. You'll need to change the file path to suit your computer's setup. Sorry, as I am not a programmer, I dont understand a lot of this but my need was so great that I had to do this :)

Since long I had been looking for a good program in this relation. Something which could send both text and /or mouse actions on typing keywords. I think I have it now. Below is a simple input gui for the code to do text replacement, if you want to execute code, just select the second option for code.

I have divided the original code into multiple files so as to be able to work. I am not a programmer so my attempts in creating a full fledged program will be futile. This solution works for me, change it to suit your individual needs.

You will require:

* Basic knowledge of scripting (if you know AHK or any other language this will be easy)

* Autoit.exe

* Auto-it Editor

* autotextmain.au3 - put in "\program files\autoit3\include\"

* autotextcode.au3 - put in "\program files\autoit3\include\"

* autotextfunctions.au3 - put in "\program files\autoit3\include\"

* autotextform.au3 - put in "\program files\autoit3\include\"

* autotextmain.au3

; Authors: Manadar, GarryFrost
; Contributor: WideBoyDixon
; Gui: Celestialspring

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <autotextcode.au3>
#include <autotextfunctions.au3>

#include-once

Dim $hHook
Dim $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
Dim $hmod = _WinAPI_GetModuleHandle(0)
Dim $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
Dim $buffer = ""
Dim $hotstrings[1]
Dim $hotfuncs[1]
Dim $hWnd = GUICreate("")
GUIRegisterMsg($WM_KEYDOWN, "_GUIKeyProc")


;; ==========================
;; This is your actual script.
;; ==========================

;#include <HotString.au3>


HotStringSet("this one","this one")








While 1
	Sleep(10)
WEnd

* autotextcode.au3

Func HotStringSet($hotstring, $func)
	_ArrayAdd($hotstrings, $hotstring)
	_ArrayAdd($hotfuncs, $func)
EndFunc

Func EvaluateKey($keycode)
	If (($keycode > 64) And ($keycode < 91)) _; A - Z
			Or (($keycode > 47) And ($keycode < 58)) Then; 0 - 9
		$buffer &= Chr($keycode)
		$buffer = StringRight($buffer, 50)

		_CheckHotkeys($buffer)
	EndIf
EndFunc  ;==>EvaluateKey

Func _CheckHotkeys($s)
	For $i = 0 to UBound($hotstrings)-1
		if ( $hotstrings[$i] = StringRight($s, StringLen($hotstrings[$i])) ) Then
			Call($hotfuncs[$i])
		EndIf
	Next
EndFunc

Func _GUIKeyProc($hWnd, $Msg, $wParam, $lParam)
	EvaluateKey(Number($wParam))
EndFunc

;===========================================================
; callback function. This function must return as quickly as possible or it will stall and block user input
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
	Local $tKEYHOOKS
	$tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
	If $nCode < 0 Then
		Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
	EndIf
	If $wParam = $WM_KEYDOWN Then
		$vkKey = DllStructGetData($tKEYHOOKS, "vkCode")
		_WinAPI_PostMessage($hWnd, $WM_KEYDOWN, $vkKey, 0)
	EndIf
	Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc  ;==>_KeyProc

Func OnAutoItExit()
	_WinAPI_UnhookWindowsHookEx($hHook)
	DllCallbackFree($hStub_KeyProc)
EndFunc  ;==>OnAutoItExit

* autotextfunctions.au3

[code

Func finally()
send("{BS 7}")
send("Text")
EndFunc







][/code]
* autotextform.au3 - This is your GUI which can be converted into Exe file

#include <file.au3>

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Auto-it Autotext", 352, 418)
$Label1 = GUICtrlCreateLabel("Code or Full Text", 17, 156, 308, 33, BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE)
$Input_chooser = GUICtrlCreateLabel("Input Type", 17, 109, 104, 33, BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE)
$Shortcutkeylabel = GUICtrlCreateLabel("Shortcut key", 17, 60, 104, 33, BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE)
$Main_label = GUICtrlCreateLabel("Auto-it Autotext", 17, 8, 308, 33, BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE)
$Shortcut_input = GUICtrlCreateInput("", 137, 64, 191, 21)
$Combo1 = GUICtrlCreateCombo("Please select", 136, 112, 191, 25)
GUICtrlSetData(-1, "Text|Code")
$code_input = GUICtrlCreateEdit("", 17, 200, 308, 170)
GUICtrlSetData(-1, "")
$ok_button = GUICtrlCreateButton("Ok", 25, 392, 97, 25, $WS_GROUP)
$Cancel_button = GUICtrlCreateButton("Cancel", 201, 392, 95, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###









While 1

	$Msg = GUIGetMsg()

	Select
		Case $Msg = $GUI_EVENT_CLOSE
			Exit


		Case $Msg = $Cancel_button
			Exit

			Case $Msg = $ok_button And $codeinputread = ""
				Exit

			Case $Msg = $ok_button And $textinputread = ""
				Exit

		Case $Msg = $ok_button And GUICtrlRead($Combo1) = "Text"
			$shortinputfile = ("D:\Program Files\AutoIt3\Include\autotextmain.au3")
			$codeinputfile = ("D:\Program Files\AutoIt3\Include\autotextfunctions.au3")
			$shortinputread = GUICtrlRead($Shortcut_input)
			$codeinputread = GUICtrlRead($code_input)
			$textinputread = GUICtrlRead($Combo1)
			$code_inputread = GUICtrlRead($Combo1)

		; opening files
			FileOpen($shortinputfile, 1)
			FileOpen($codeinputfile, 1)

		; Execute($writeshortcutfile)

			_FileWriteToLine($shortinputfile, 39, @CRLF & "HotStringSet(" & """" & $shortinputread & """" & "," & """" & $shortinputread & """" & ")", 1)



		;Execute($writetextfile)

			$len = StringLen($shortinputread)
			FileWrite($codeinputfile, "Func " & $shortinputread & "(" & ")" & @CRLF & "send(" & """" & "{BS " & $len & "}" & """" & ")" & @CRLF & "send(" & """" & $codeinputread & """" & ")" & @CRLF & "EndFunc" & @CRLF & @CRLF)

		; Execute closefiles

			FileClose($shortinputfile)
			FileClose($codeinputfile)


			Exit

		Case $Msg = $ok_button And GUICtrlRead($Combo1) = "Code"
			$shortinputfile = ("D:\Program Files\AutoIt3\Include\autotextmain.au3")
			$codeinputfile = ("D:\Program Files\AutoIt3\Include\autotextfunctions.au3")
			$shortinputread = GUICtrlRead($Shortcut_input)
			$codeinputread = GUICtrlRead($code_input)
			$textinputread = GUICtrlRead($Combo1)
			$code_inputread = GUICtrlRead($Combo1)

		; opening files
			FileOpen($shortinputfile, 1)
			FileOpen($codeinputfile, 1)

		; Execute($writeshortcutfile)

			_FileWriteToLine($shortinputfile, 39, @CRLF & "HotStringSet(" & """" & $shortinputread & """" & "," & """" & $shortinputread & """" & ")", 1)



		;Execute($writecodefile)

			$len = StringLen($shortinputread)

			FileWrite($codeinputfile, "Func " & $shortinputread & "(" & ")" & @CRLF & "send(" & """" & "{BS " & $len & "}" & """" & ")" & @CRLF & $codeinputread & @CRLF & "EndFunc" & @CRLF & @CRLF)

		; Execute closefiles



			FileClose($shortinputfile)
			FileClose($codeinputfile)


			Exit

	EndSelect



WEnd;### Tidy Error -> switch is never closed in your script.;### Tidy Error -> func is never closed in your script.;### Tidy Error -> case is never closed in your script.

Gui screenshot:

auotit.jpg

Your feedback is much appreciated.

Thanks.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • well you can add a GPU for around $500, that's still around the price of Steam Machine but overall significantly better in performance.
    • Fresh CachyOS install with Niri - I guess it's a little orange, but I'm working on it
    • FastStone Image Viewer 8.5 by Razvan Serea FastStone Image Viewer is a fast, stable, user-friendly image browser, converter and editor. It has a nice array of features that include image viewing, management, comparison, red-eye removal, emailing, resizing, cropping, retouching and color adjustments. Its innovative but intuitive full-screen mode provides quick access to EXIF information, thumbnail browser and major functionalities via hidden toolbars that pop up when your mouse touches the four edges of the screen. Other features include a high quality magnifier and a musical slideshow with 150+ transitional effects, as well as lossless JPEG transitions, drop shadow effects, image annotation, scanner support, histogram and much more. It supports all major graphic formats (BMP, JPEG, JPEG 2000, animated GIF, PNG, PCX, PSD, EPS, TIFF, WMF, ICO and TGA) and popular digital camera RAW formats (CRW, CR2, NEF, PEF, RAF, MRW, ORF, SRF, ARW, SR2, RW2 and DNG). FastStone Image Viewer features: Image browser and viewer with a familiar Windows Explorer-like user interface Support for many popular image formats and PDF viewing True Full Screen viewer with convenient image zoom support and unique fly-out menu panels Crystal-clear and customizable one-click image magnifier Powerful image editing tools: Resize/resample, rotate/flip, crop, sharpen/blur, adjust lighting/colors/curves/levels etc. Eleven re-sampling algorithms to choose from when resizing images Image color effects: gray scale, sepia, negative, Red/Green/Blue adjustment Image special effects: drop shadow, framing, bump map, sketch, oil painting, lens Draw texts, lines, highlights, rectangles, ovals and callout objects on images Clone Stamp and Healing Brush Superior red-eye effect removal/reduction with completely natural looking end result Multi-level Undo/Redo capability Single click to switch between best fit and actual size mode Image management, including file tagging, rating and drag-and-drop to copy/move/re-arrange files Histogram display with color counter feature Compare images side-by-side (up to 4 at a time) to easily cull those forgettable shots Image EXIF metadata support (plus comment editing for JPEGs) Configurable batch processing to convert/rename large or small collections of images Slideshow with 150+ transition effects and music support (MP3, WMA, WAV...) Create efficient image attachments for emailing to family and friends Print images with full page-layout control Create fully configurable contact sheets Create memorable artistic image montages from your family photos for personalized desktop wallpapers (Wallpaper Anywhere) Acquire images from scanners. Support batch scanning to PDF, TIFF, JPEG and PNG Versatile screen capture capability Powerful Save As interface to compare image quality and control generated file size Run favorite external editors with one keystroke from within Image Viewer Offer portable version of the program which can be run from a removable storage device Configurable mouse wheel support Support themes (bright, gray and dark) Support dual-monitor configurations Support touch interface (tap, swipe, pinch) Support dual instances Play video and audio files (Third party codecs may be required for old versions of Windows) And much more... FastStone Image Viewer 8.5 changelog: Added support for SVG format Added Start importing automatically and Handle duplicate file names automatically options to the Import Photos and Videos tool WebP files can now be rotated and saved with a single click Enhanced dark theme support in the PDF viewer Fixed a bug where some links in PDF files were not clickable Other improvements and bug fixes Download: FastStone Image Viewer 8.5 | Portable | ~15.0 MB (Freeware) View: FastStone Image Viewer Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Rookie
      DaviKar went up a rank
      Rookie
    • Dedicated
      HidekoYamamoto94 earned a badge
      Dedicated
    • One Month Later
      timbobit earned a badge
      One Month Later
    • One Month Later
      nates earned a badge
      One Month Later
    • Week One Done
      Almohandis earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      461
    2. 2
      +Edouard
      160
    3. 3
      PsYcHoKiLLa
      110
    4. 4
      Michael Scrip
      85
    5. 5
      Steven P.
      69
  • Tell a friend

    Love Neowin? Tell a friend!