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.