AutoHotkey Community

It is currently May 27th, 2012, 11:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: April 8th, 2004, 8:54 am 
Online

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
This script will change ur shortcut text to something u've defined, that too in real time right when u're typing... works in any application.

This script utilises the input cmd, and is much easier to understand than the earlier complex script (which i've moved to the bottom).

The added benefit is that you'll have an option of using a 'prefix' character for triggers which are more common words and not using it for others.

typing btw anywhere will change it to by the way
and prefixing mail with ` will change it to mymail@server.com
(without quotes)

keep this in triggers.ini
Code:
[Triggers]
`mail=mymail@server.com
btw=by the way
otoh=on the other hand
plz=please

(mind that no empty lines should be present and 'trigger=some text' should not have extra spaces like 'trigger = some text', around the equals sign)

this is the script

Code:
SetTimer, AutoReplace, on
SetBatchLines, 10ms

;_______Building shortcut text list

Trigger0 = 1
Loop, Read, %a_scriptdir%\Triggers.ini
{
        IfEqual, A_Index, 1, Continue
        StringGetPos, EqPos, A_LoopReadLine, =
        StringLeft, CT, A_LoopReadLine, %EqPos%
        Trigger%A_Index% = %CT%
        Triggers = %Triggers%`,%CT%
        Trigger0 ++
}
;___________________________________________

;___________________________________________
;_____Shortcut text_________________________

AutoReplace:
        SetTimer, AutoReplace, off
        SetKeyDelay, -1
       
        ;more specific trigger texts can be added here:
        Input, UserInput, *V, {ESC}{ENTER}, %Triggers%
       
        Loop, %Trigger0%
        {
                IfEqual, A_Index, 1, Continue
                StringTrimRight, CT, Trigger%A_Index%, 0
                IfInString, UserInput, %CT%
                {
                        StringLen, Tlen, CT
                        IniRead, ToSend, %a_scriptdir%\Triggers.ini, Triggers, %CT%
                        StringReplace, ToSend, ToSend, <s>, %a_space%, A
                        IfNotEqual, ToSend, ERROR, Send, {BS %Tlen%}%ToSend%
                        Break
                }
        }
       
        SetTimer, AutoReplace, on
Return

_________________
Image


Last edited by Rajat on May 29th, 2004, 7:05 am, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 19th, 2004, 10:11 am 
Offline

Joined: April 7th, 2004, 2:43 pm
Posts: 62
WOW this is useful.
I didn't imagine THIS was possible.
Thanks ALL!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: kick a**!!
PostPosted: May 18th, 2004, 7:28 am 
You have no idea how useful this is at my job. Thank you very much.

:D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2004, 7:58 am 
Online

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
bitxbit,

have a look here:
http://www.autohotkey.com/forum/viewtopic.php?t=200

this page shows a smaller code that works just the same.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: ugh
PostPosted: May 18th, 2004, 8:32 am 
Offline

Joined: May 18th, 2004, 7:25 am
Posts: 7
Forgive my slowness but I'm obviously doing something wrong or haven't modified it correctly. I did create the 'Triggers.ini' file but I keep getting the error message below:

Error at line 14.

Line Text: Input, UserInput, VT5L5, {tab}, %Triggers%
Error: This line does not contain a recognized action.

The program will exit.

_________________
Must nothing. There's always another way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2004, 12:34 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
You would get that error if you are using an older version of AutoHotkey.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: cool
PostPosted: May 18th, 2004, 3:49 pm 
Offline

Joined: May 18th, 2004, 7:25 am
Posts: 7
The latest version did it. Thanks.

_________________
Must nothing. There's always another way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2004, 1:17 am 
Online

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
This script is done by Chris and Jay D. Novak. Somewhat complex but really very nice script. might give u some ideas on some nifty usages.

Code:
#SingleInstance  ; Allow only one instance of the script to exist at a time.
SetBatchLines, 10ms  ; Make the script run fast but cooperatively.
SetKeyDelay, 0   ; Make keys get sent faster.

Gosub, InitTriggerList


~[::  ; This is the hotkey that starts us waiting for the user to type a triggering phrase.
TriggerStartTime = %A_TickCount%
TriggerPhrase =
TriggerPhraseLength = 0
Loop
   Gosub, GetNextChar  ; This will Exit for us when the task is finished.
return



GetNextChar:
Loop  ; Poll the specified keyboard keys every 10 ms to wait for the user to press one.
{
   Loop, parse, TriggerChars ; Check if at this instant, one of the allowed keys is pushed down.
   {
      GetKeyState, down_or_up, %A_LoopField%
      if down_or_up = U
         continue  ; Start a new iteration of this loop.
      ; The user is now pressing a key, so add it to the phrase unless it's backspace:
      if A_LoopField = `b
      {
         if TriggerPhraseLength = 0
         {
            if A_OSType = WIN32_WINDOWS  ; Windows 9x
               continue  ; Ignore backspaces if there are no chars in the phrase yet.
            ; Otherwise, the user has just backspaced over the triggering key,
            ; indicating that no triggering action is desired:
            Exit
         }
         ; Otherwise, have a backspace keystroke remove the most recent char in the phrase:
         --TriggerPhraseLength
         StringLeft, TriggerPhrase, TriggerPhrase, %TriggerPhraseLength%
         ; And now wait for the keystroke to be completed so that the backspace key,
         ; which the user is holding down, won't immediately be detected as a 2nd
         ; backspace during the next loop iteration:
         KeyUp = `b
         Gosub, WaitForKeyUp
         continue  ; Start a new iteration of this loop.
      }
      TriggerPhrase = %TriggerPhrase%%A_LoopField%
      ++TriggerPhraseLength
      ; Does the phrase now match one of the triggers in the list?
      if Trigger%TriggerPhrase% <>  ; Match found.
      {
         StringTrimLeft, ReplacementText, Trigger%TriggerPhrase%, 0  ; Retrieve the list item.
         Send, {backspace %TriggerPhraseLength%}

         ; If the OS is Windows 9x, the passthrough (~) nature of the hotkey won't work,
         ; which means that the triggering character itself will always be suppressed.
         ; So here we send an extra backspace when the OS is NT/2k/XP or beyond.
         if A_OSType <> WIN32_WINDOWS  ; i.e. it's not Windows 9x
            Send, {backspace}
         Send, %ReplacementText%
         Exit ; terminate this thread completely because we're done.
      }
      ; Otherwise, there's no match.  So if the phrase is now at its max allowed length, there
      ; is no match.  The below uses "greater than" to allow one extra keypress in case the last
      ; character is a typo and the user wants to salvage the sequence by pressing backspace:
      if TriggerPhraseLength > %MaxTriggerPhraseLength%
      {
         ; Seems better to do nothing so that the triggering key can be used normally:
         ;Send, {backspace %TriggerPhraseLength%}<invalid>
         Exit
      }
      ; Otherwise, wait for more keys.  But first wait for the user to release the current key
      ; so that this key isn't immediately detected as the next key also:
      KeyUp = %A_LoopField%
      Gosub, WaitForKeyUp
      return
   }
   Sleep, 10  ; Allow the CPU to rest between polls (doesn't much degrade reliability or responsiveness).
   TriggerElapsedTime = %A_TickCount%
   TriggerElapsedTime -= %TriggerStartTime%
   if TriggerElapsedTime > %TriggerTimeout%
      Exit  ; Terminate this thread for performance reasons.
}
return



WaitForKeyUp:
Loop
{
   GetKeyState, down_or_up, %KeyUp%
   if down_or_up = U
      return
   Sleep, 10
}
return



InitTriggerList:
; Here list all the characters that would ever exist in a triggering phrase.
; Not that these are not case sensitive because both upper and lower case letters will be detected.
; Note that backspace (`b) is also in the list so that it can be detected as an "undo" character.
TriggerChars = abcdefghijklmnopqrstuvwxyz0123456789`b

; This is the length of the largest triggering abbreviation defined in the list below:
MaxTriggerPhraseLength = 3

; How many milliseconds to wait for the user to complete a triggering phrase before timing out:
TriggerTimeout = 5000

; USA states:
TriggerAL = Alabama
TriggerAK = Alaska
TriggerAZ = Arizona
TriggerAR = Arkansas
TriggerCA = California
TriggerCO = Colorado
TriggerCT = Connecticut
TriggerDE = Delaware
TriggerDC = District of Columbia
TriggerFL = Florida
TriggerGA = Georgia
TriggerHI = Hawaii
TriggerID = Idaho
TriggerIL = Illinois
TriggerIN = Indiana
TriggerIA = Iowa
TriggerKS = Kansas
TriggerKY = Kentucky
TriggerLA = Louisiana
TriggerME = Maine
TriggerMD = Maryland
TriggerMA = Massachusetts
TriggerMI = Michigan
TriggerMN = Minnesota
TriggerMS = Mississippi
TriggerMO = Missouri
TriggerMT = Montana
TriggerNE = Nebraska
TriggerNV = Nevada
TriggerNH = New Hampshire
TriggerNJ = New Jersey
TriggerNM = New Mexico
TriggerNY = New York
TriggerNC = North Carolina
TriggerND = North Dakota
TriggerOH = Ohio
TriggerOK = Oklahoma
TriggerOR = Oregon
TriggerPA = Pennsylvania
TriggerRI = Rhode Island
TriggerSC = Sourth Carolina
TriggerSD = South Dakota
TriggerTN = Tennessee
TriggerTX = Texas
TriggerUT = Utah
TriggerVT = Vermont
TriggerVA = Virginia
TriggerWA = Washington
TriggerWV = West Virginia
TriggerWI = Wisconsin
TriggerWY = Wyoming

; Countries:
TriggerUK = United Kingdom

; Misc:
TriggerAHK = AutoHotkey
return

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2004, 1:16 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Nice work on the revised script (at the top of this topic)! The only improvement I can see is to have something like {Enter} be an EndKey so that the 16 KB limit of the Input command is never reached, though most users would probably press Escape at least once for every 16 KB of text they type.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2004, 7:03 am 
Online

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Quote:
The only improvement I can see is to have something like {Enter} be an EndKey


done. by the way weren't u going to do something regarding making the parameter unlimited?

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2004, 12:34 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Yes, that is a planned feature. It's lower on the priority list since it's easy to make it unlimited by putting the command in a Loop.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2007, 2:41 pm 
Offline

Joined: September 2nd, 2007, 2:39 pm
Posts: 2
Hi - trying to put a pause in the output with this script.
Should this work?

count123=1{Sleep, 1000}2{Sleep, 1000}3

Should show 123 with 1 second delays but doesn't seem to work for me.
Any help appreciated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2007, 4:41 pm 
Offline

Joined: May 21st, 2007, 4:47 pm
Posts: 85
Here is a similar AHK program of my own with a GUI to add, modify or delete triggers.

Enjoy!

_________________
Normand Lamoureux


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2007, 4:50 pm 
Offline

Joined: May 21st, 2007, 4:47 pm
Posts: 85
Available in English.
Easy to translate.
Here is a screenshot:
Image

_________________
Normand Lamoureux


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2007, 6:10 pm 
Offline

Joined: September 2nd, 2007, 2:39 pm
Posts: 2
ok - how about a link?

Any can one add delays and other control characters (eg {enter}) with your program?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: nomissenrojb, Rajat and 56 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group