 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Laszlo
Joined: 14 Feb 2005 Posts: 4065 Location: Pittsburgh
|
Posted: Mon Dec 05, 2005 1:26 am Post subject: Incremental search for text to send |
|
|
This short script sends predefined pieces of text found by the beginnings of their first word.
It is based on the built-in incremental search functionality of ListBoxes, so its features list longer than the script itself.
The text-pieces are delimited by pipe, "|", can contain spaces, special characters.
The last entry has to be "[" for technical reasons.
When the Ctrl-Space HotKey is hit, the script takes the (partial) word left to the insertion point and looks in the user-defined List if there are continuations.
- If there is none, nothing happens, otherwise a ListBox pops up with the first match highlighted.
Usually there is just one match, so keeping the Ctrl key pressed & hitting the space bar again sends the selected text to the current window (the most convenient way, but Enter works, too).
If you keep typing, an incremental search highlights always the first match, while the original window shows the typed text, which is being used to search for the long pieces of text. Here you can type space and other characters, too, which would delimit the initial word.
If there is no more match, the search aborts, leaving the typed search text intact.
Up, Down and Mouse clicks change the selection in the ListBox.
Mouse click on Scroll bar or the mouse wheel scrolls the text.
Double click on an entry in the list box sends that text to the window, erasing the text typed after the last Ctrl-Space.
Ctrl-Space:
1. No abbreviation defined: no effect.
2. There are abbreviations: pop up GUI, first match selected in a ListBox.
-- a. 2nd Ctrl-Space or Enter: Send selected text from List, replace typed text
-- b. Esc or TAB: Return, no text insertion
-- c. Keep typing: Select incremental matches, keys echoed in original window.
---- If there is no more match, exit
-- d. BackSpace:
---- If no more key left since Ctrl-Space, exit
---- Delete keys typed since Ctrl-Space activation, update selection
-- e. Up, Down, Mouse click: change selection
-- f. Double click sends the corresponding text
Limitations:
- Only works in applications using Shift-Ctrl-Left to select the word left of the insertion point
- Ctrl-X/Send to cut/paste might have side effects (change indentation, paragraph format...)
- Changing the active window makes text sent there
ToDo:
- Replace GoTo's with functions, for the purists
- Suspend while other windows are active
- Save/Load list from/to a .ini file
- Dynamically Add/Remove entries from the list
- Movable, resizable GUI
- Save/Load GUI position
| Code: | Process Priority,,High ; little load, but need fast reaction
Autotrim OFF ; Space can be appended
; Your text pieces. Last "[" needed for no match detection & move first match to the top
List = Péter-Pál|South America|South Carolina|South Dakota|South Pole*|Southern|Souter, David (American jurist & statesman)|time|XEROX|Zeppelin|####|[
Gui -Caption AlwaysOnTop
Gui Margin, 2,2
Gui Add, ListBox, x2 y2 r5 w180 Sort vChoice gClicked, %List%
Return
^Space:: ; Search/send-text HotKey
ek =
ClipBoard = ; empty the ClipBoard
Send ^+{Left}^x ; cut out word on the left
ClipWait 2 ; wait until it gets to the ClipBoard
c = %ClipBoard% ; shorthand
SendRaw %c% ; send word back (^v has side effects)
Gui Show, x0 y200 ; show GUI: <-- your favorite location!
WinGet GuiID, ID, A ; ID of the GUI for ControlSend below
Send !{TAB} ; back to caller
Loop
{ ; key from the previous Loop iteration
If ek in Up,Down ; navigate in the ListBox
ControlSend ListBox1, {%ek%}, ahk_id %GuiID%
Else { ; select bottom entry, then abbreviation
GuiControl ChooseString,Choice,[ ;... to show it on top
GuiControl ChooseString,Choice,%c%
GuiControlGet Choice ; get selected
If Choice = [ ; still on "[" if no match
GoTo OUT ; exit
}
Input k, I L1 M, {Enter}{Esc}{TAB}{BS}{Up}{Down}
StringTrimLeft ek, ErrorLevel, 7 ; Remove "Endkey:"
If ek in Escape,TAB
GoTo OUT ; exit
If ek = Enter
GoTo SendText ; send full text, exit
If (k = " " and GetKeyState("Ctrl"))
GoTo SendText ; send full text, exit
If ek = Backspace
{
IfEqual c,, GoTo Out ; all have been deleted
StringTrimRight c,c,1 ; remove last char
Send {BS} ; delete last char in application window
}
Send %k% ; echo key in application window
c = %c%%k% ; incremental search
}
Clicked: ; @ mouse click in the ListBox
IfNotEqual A_GuiControlEvent,DoubleClick, Return
SendText:
Gui Submit
Send % "{BS " StrLen(c) "}" ; remove typed abbreviation
SendRaw %Choice% ; send full text
OUT:
Gui Show, Hide ; hide GUI
Return |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10474
|
Posted: Mon Dec 05, 2005 1:44 pm Post subject: |
|
|
| Looks great and very well documented. I expect to use it for at least one future script. |
|
| Back to top |
|
 |
Harrie
Joined: 04 Aug 2005 Posts: 41
|
Posted: Wed Dec 07, 2005 3:58 pm Post subject: |
|
|
| Very beautiful from the end-user's point of view indeed! Great script! Why, how perfect for putting in a whole list of doctor names or the like. Just tried it out by putting several "Dr. So-and-So's in the script. Might change it around and leave the "Dr." out of the script since MS Word wants to see a period as a word. Truly looking forward to experimenting with this jewel. |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4065 Location: Pittsburgh
|
Posted: Wed Dec 07, 2005 4:42 pm Post subject: |
|
|
| Thanks for the compliments! If all of your abbreviations end with a period or comma, or you always use more than one letter abbreviations, you could modify the script (4th line of the hotkey subroutine) to send +{Left}^+{Left}^x instead. Or, check if the ClipBoard contains a punctuation mark only, and than do this longer selection. |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Oct 22, 2007 1:54 pm Post subject: Re: Incremental search for text to send |
|
|
| Laszlo wrote: | | - Save/Load list from/to a .ini file |
Dear Laszlo,
This script seems very useful to me for translation work, see my post on:
http://www.autohotkey.com/forum/topic24808.html
Have you, by any chance, implemented the feature that loads a wordlist from a file? It would enable me to use large wordlists/dictionaries with this script.
Kind regards,
Jilt Dijk |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 617
|
|
| Back to top |
|
 |
Jiltdijk
Joined: 04 Sep 2006 Posts: 22
|
Posted: Mon Oct 22, 2007 10:04 pm Post subject: |
|
|
Dear HugoV,
Thank you for your tip. I've downloaded Kollektor 03, it's indeed very much like the thing I was looking for.
I wonder if it's possible to link the word you find in the list to it's translation(s) and only paste this translation into your document instead of the searched word.
The way I'd use it now for translations is to edit Collection.txt like this
book - boek
table - tafel
insert the entry and remove the source part of it.
Jilt |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 617
|
Posted: Tue Oct 23, 2007 7:50 am Post subject: |
|
|
Look up the line
| Code: |
ControlSend, %CursorIn%,{Control down}v{Control up}, AHK_ID%ActiveWindow%
|
in the script and insert this code just above it:
| Code: |
IfInString,Clipboard,- ; remove everything after this character
{
StringGetPos, MarkerPos, Clipboard,-
StringLeft, Clipboard, Clipboard, %MarkerPos%
}
|
What it does is it checks if there is a - character in the string,
and if so it removes everthing after the - character.
So you type 'boe' and you can select 'book - boek' from the
result list, but only 'book' will be pasted. With a little work you
could make it work both ways, e.g. just pressing Enter makes
it paste 'book' and pressing Shift Enter it would paste 'boek'
I hope this helps. Another script you may want to look at, which
is much more complicated but more along the lines of your orignal
request is Isense or IntelliSense
You start typing and a popup appears after 3 letters or so.
But you would need to modify those scripts to make them
work with a dictionary. (would be an interesting project for
the coming winter months)
Isense:
http://www.autohotkey.com/forum/viewtopic.php?t=12985
Intellisense is installed in the Autohotkey directory:
Program Files\AutoHotkey\Extras\Scripts\IntelliSense.ahk
you can search the forum for variations of this script as well. |
|
| Back to top |
|
 |
Jiltdijk
Joined: 04 Sep 2006 Posts: 22
|
Posted: Tue Oct 23, 2007 12:33 pm Post subject: |
|
|
Thanks for the modification.
I definitely want to look into ISense later, but first I'm getting back to my translation assignment and see how this works!
Jilt |
|
| Back to top |
|
 |
totalmig
Joined: 22 Jul 2008 Posts: 98
|
Posted: Thu Nov 13, 2008 1:16 pm Post subject: |
|
|
Hi.
Thanks for making this great script, has been really usefull for me.
I just tried using it along with some gui, and that messes it up totally. Whenever i click ctrl + space i changes focus to another window. If i run your script, and then run the gui in another script the it runs just fine. Don't know what i should do to get it working, hope someone is able to point it out.
| Code: | #Include CoHelper.ahk
setbatchlines, -1
Process Priority,,High ; little load, but need fast reaction
;Autotrim OFF
Gui, Add, Text, x36 y30 w360 h30 , Print 10 lejligheder af gangen
Gui, Add, Edit, x36 y70 w180 h20 v9,
Gui, Add, Edit, x36 y100 w180 h20 v5,
Gui, Add, Edit, x36 y130 w180 h20 v1 ,
Gui, Add, Edit, x36 y160 w180 h20 v2,
Gui, Add, Edit, x36 y190 w180 h20 v3,
Gui, Add, Edit, x36 y220 w180 h20 v4,
Gui, Add, Edit, x36 y250 w180 h20 v6,
Gui, Add, Edit, x36 y280 w180 h20 v7,
Gui, Add, Edit, x36 y310 w180 h20 v8,
Gui, Add, Edit, x36 y340 w180 h20 v10,
Gui, Show, x356 y228 h486 w498, MegaPrint
; Your text pieces. Last "[" needed for no match detection & move first match to the top
Loop Q:\reception\*.xls
{
pattern = (.*)Nřgleliste
check := RegExMatch(A_LoopFileName, pattern)
if check > 0
Nřgleliste = %A_loopfilefullpath%
}
CoInitialize()
pxl := ActiveXObject("Excel.Application")
;pawb := Invoke(Invoke(pxl, "Workbooks"), "Add")
;paws := Invoke(Invoke(pxl, "Worksheets"), "Item", 1)
;pcls := Invoke(paws, "Cells")
pawb := Invoke(Invoke(pxl, "Workbooks"), "Open", "" nřgleliste "")
paws := Invoke(Invoke(pxl, "Worksheets"), "Item", 1)
pcls := Invoke(paws, "Cells")
Letter = 2
Line = 1
Loop, 600
{
openedcell := Invoke(Invoke(pcls, "Item", Line, Letter), "Value")
list = %openedcell%|%list%
Line := Line + 1
}
list = %list%[
;List = Péter-Pál|South America|South Carolina|South Dakota|South Pole*|Southern|Souter, David (American jurist & statesman)|time|XEROX|Zeppelin|####|[
Gui -Caption AlwaysOnTop
Gui Margin, 2,2
Gui Add, ListBox, x2 y2 r5 w180 Sort vChoice gClicked, %List%
Return
^Space:: ; Search/send-text HotKey
ek =
ClipBoard = ; empty the ClipBoard
Send ^+{Left}^x ; cut out word on the left
ClipWait 2 ; wait until it gets to the ClipBoard
c = %ClipBoard% ; shorthand
SendRaw %c% ; send word back (^v has side effects)
Gui Show, x0 y200 ; show GUI: <-- your favorite location!
WinGet GuiID, ID, A ; ID of the GUI for ControlSend below
Send !{TAB} ; back to caller
Loop
{ ; key from the previous Loop iteration
If ek in Up,Down ; navigate in the ListBox
ControlSend ListBox1, {%ek%}, ahk_id %GuiID%
Else { ; select bottom entry, then abbreviation
GuiControl ChooseString,Choice,[ ;... to show it on top
GuiControl ChooseString,Choice,%c%
GuiControlGet Choice ; get selected
If Choice = [ ; still on "[" if no match
GoTo OUT ; exit
}
Input k, I L1 M, {Enter}{Esc}{TAB}{BS}{Up}{Down}
StringTrimLeft ek, ErrorLevel, 7 ; Remove "Endkey:"
If ek in Escape,TAB
GoTo OUT ; exit
If ek = Enter
GoTo SendText ; send full text, exit
If (k = " " and GetKeyState("Ctrl"))
GoTo SendText ; send full text, exit
If ek = Backspace
{
IfEqual c,, GoTo Out ; all have been deleted
StringTrimRight c,c,1 ; remove last char
Send {BS} ; delete last char in application window
}
Send %k% ; echo key in application window
c = %c%%k% ; incremental search
}
Clicked: ; @ mouse click in the ListBox
IfNotEqual A_GuiControlEvent,DoubleClick, Return
SendText:
Gui Submit
Send % "{BS " StrLen(c) "}" ; remove typed abbreviation
SendRaw %Choice% ; send full text
OUT:
Gui Show, Hide ; hide GUI
Return |
Thanks  |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 617
|
Posted: Thu Nov 13, 2008 1:34 pm Post subject: |
|
|
You have two guis, but you only define one so to speak. Read up on multiple GUIs http://www.autohotkey.com/docs/commands/Gui.htm#MultiWin
Add a Return below your first GUI, and you may also need to move sections of the script as it will stop after the first Gui (if you add return) and thus will not process the search ... _________________ When parsing a CSV file use Loop, parse, Inputvar, CSV! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|