AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Use shortcut text realtime
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Thu Apr 08, 2004 7:54 am    Post subject: Use shortcut text realtime Reply with quote

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

_________________


Last edited by Rajat on Sat May 29, 2004 6:05 am; edited 5 times in total
Back to top
View user's profile Send private message
Payam



Joined: 07 Apr 2004
Posts: 61

PostPosted: Mon Apr 19, 2004 9:11 am    Post subject: Reply with quote

WOW this is useful.
I didn't imagine THIS was possible.
Thanks ALL!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
bitxbit
Guest





PostPosted: Tue May 18, 2004 6:28 am    Post subject: kick a**!! Reply with quote

You have no idea how useful this is at my job. Thank you very much.

Very Happy
Back to top
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Tue May 18, 2004 6:58 am    Post subject: Reply with quote

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.
_________________
Back to top
View user's profile Send private message
bit_x_bit



Joined: 18 May 2004
Posts: 7

PostPosted: Tue May 18, 2004 7:32 am    Post subject: ugh Reply with quote

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.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Tue May 18, 2004 11:34 am    Post subject: Reply with quote

You would get that error if you are using an older version of AutoHotkey.
Back to top
View user's profile Send private message Send e-mail
bit_x_bit



Joined: 18 May 2004
Posts: 7

PostPosted: Tue May 18, 2004 2:49 pm    Post subject: cool Reply with quote

The latest version did it. Thanks.
_________________
Must nothing. There's always another way.
Back to top
View user's profile Send private message
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Wed May 26, 2004 12:17 am    Post subject: Reply with quote

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

_________________
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Fri May 28, 2004 12:16 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Sat May 29, 2004 6:03 am    Post subject: Reply with quote

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?
_________________
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Sat May 29, 2004 11:34 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
danson



Joined: 02 Sep 2007
Posts: 2

PostPosted: Sun Sep 02, 2007 1:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Normand



Joined: 21 May 2007
Posts: 63

PostPosted: Sun Sep 02, 2007 3:41 pm    Post subject: Reply with quote

Here is a similar AHK program of my own with a GUI to add, modify or delete triggers.

Enjoy!
_________________
Normand Lamoureux
Back to top
View user's profile Send private message
Normand



Joined: 21 May 2007
Posts: 63

PostPosted: Sun Sep 02, 2007 3:50 pm    Post subject: Reply with quote

Available in English.
Easy to translate.
Here is a screenshot:

_________________
Normand Lamoureux
Back to top
View user's profile Send private message
danson



Joined: 02 Sep 2007
Posts: 2

PostPosted: Sun Sep 02, 2007 5:10 pm    Post subject: Reply with quote

ok - how about a link?

Any can one add delays and other control characters (eg {enter}) with your program?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group