AutoHotkey Community

It is currently May 26th, 2012, 9:56 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 27th, 2009, 6:23 am 
Offline

Joined: February 20th, 2007, 1:37 pm
Posts: 198
Location: D.C.
Image
-- Uh, revised 09-27-09 to use send instead of pasting, and timer fixed. If anybody can provide a better solution to my timer, I would appreciate it. It's just there to keep the script informed of what the active window was before clicking on the tagger app itself. I had thought there was an ahk code for that but I didn't see it last night.

This is yet another generic tag or textstring inserter nearly identical in function to the cliptext window in a couple good text editors I've used like Texturizer or Textpad, except you can use this with any program (or designate just one). It's my first ListView. Loads your choice of textfile for any textsending purpose, formatted like this below. Autosorted alphabetically. Note the <br> tag which has no closing tag has no # sign, and note the # sign's placement for tags that do require a closing tag.

Quote:
a_name | <a name="?">#</a>
break | <br>
center | <center>#</center>
cite | <cite>#</cite>
code | <code>#</code>
definition | <dfn>#</dfn>
definition list | <dl>#</dl>
div | <div align="left">#</div>


And you can double click on a row or press hotkeys Win-Alt-t to activate the tagger and then goto your cliptext's row either by scrolling or by pressing the first letter of the name, as standard to listviews I guess, then press enter to send the string in column 2. The # sign is of course for the generic cliptext function of cut from editor, paste first half of col 2, up to where the # is, paste text cut from editor, paste second half of column 2. You know, basic tags thing. You can also designate a solo target for the clips, or deselect that target and have the script apply to all windows (using menu).

Code:
#NoEnv
SendMode Input
SetTimer,GetActiveWindow, 30

ButtonLoadFile:  ;;This is where we select the textfile for the tags
Gui Destroy
Gui +OwnDialogs  ; Forces user to dismiss the following dialog before using main window.
FileSelectFile, Nestcepas,, 3, Select a file to read:
if not Nestcepas  ; The user canceled the dialog.
    return
   
; Allow the user to maximize or drag-resize the window:
Gui +Resize

Menu, MyMenu, Add, Load File, ButtonLoadFile
Menu, TargetMenu, Add, Select Target, ButtonSelect_Target
Menu, TargetMenu, Add, DeSelect, Deselect_Target
Menu, MyMenu, Add, Target, :TargetMenu
Gui, Menu, MyMenu


Gui, Add, Button, Hidden Default H0 W0, OK
Gui, Add, ListView, xm r20 w200 vMyListView gMyListView Grid, Name | Text ; r20 w150

LV_ModifyCol()  ; Auto-size each column to fit its contents.

; This is where we get the items from the text file:

FileRead, Durant, %Nestcepas% ;Read file into var Durant

Loop, Parse, Durant, `n, `r ; This should get each tag one at a time
{
   If A_LoopField =
   Continue
   Alpha = %A_Index%
    Will = %A_Loopfield%
   Loop, Parse, Will, |
      {
      If A_Index = 1
         Gomer%Alpha% = %A_LoopField%
      If A_Index = 2
         Goober%Alpha% = %A_LoopField%
      }
      LV_Add("",Gomer%Alpha%,Goober%Alpha%)
      LV_ModifyCol()  ; Auto-size each column to fit its contents.
      LV_ModifyCol(3, 60) ; Make the Size column at little wider to reveal its header.
;GuiControl, +Redraw, MyListView  ; Re-enable redrawing (it was disabled above).
}
      
; performs alphabetical sort:
LV_ModifyCol(1, "Sort", Name)
Gui, +AlwaysOnTop
Gui, Show
return


DeSelect_Target:
Title =
SetTimer,GetActiveWindow,50
Return


ButtonOK:
GuiControlGet, FocusedControl, FocusV
if FocusedControl <> MyListView
    return
Durham := % LV_GetNext(0, "Focused")
LV_GetText(RowText2, Durham,2)
Goto Gogo



if A_GuiEvent = DoubleClick
Goto MyListView

MyListView:
SetKeyDelay,11,41
DialNine = %Clipboard%
Clipboard =
LV_GetText(RowText2, A_EventInfo,2)  ; Get the text of the second field.
;MsgBox, Rowtext = %Rowtext% `n A_EventInfo = %A_EventInfo%
Gogo:
   WinActivate,%Title%
   Raster := RowText2
   IfInString, Raster, #
      {
      Loop,Parse,Raster, #
         {
         If A_Index = 1
            {
            Defender := A_LoopField
            Send,^x
            Xevious := Clipboard
            Clipboard =
            }
         Else
            {
            Asteroids := A_LoopField
            }
         }
            Clipboard := % Defender . Xevious . Asteroids
         }
   IfNotInstring, Raster, #
      {
      Clipboard = %Raster%
      }
   SetKeyDelay,-1,-1
   Send,%Clipboard%
   Send,%A_Space%
      Clipboard =
   Clipboard = %DialNine%
SetKeyDelay,11,11
Return

GuiSize:  ; Expand or shrink the ListView in response to the user's resizing of the window.
if A_EventInfo = 1  ; The window has been minimized.  No action needed.
    return
; Otherwise, the window has been resized or maximized. Resize the ListView to match.
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 20) ;%
return

GuiClose:  ; When the window is closed, exit the script automatically:
^+#Escape::
ExitApp

Clicky:
MsgBox,After pressing OK, click on the Edit field of the word processor or text editor application you would like to have your time stamps placed in.  If you don't have that application open now, do so before pressing the "OK" button in this message box. (Hint, The Edit field is where the actual document is displayed.)

ButtonSelect_Target:
SetTimer,GetActiveWindow,Off
Title =
KeyWait,LButton,D
MouseGetPos, , , id, control
WinGetTitle, Title, ahk_id %id%
WinGetClass, class, ahk_id %id%
Return

#!t::
WinGetActiveTitle,Title
If Title = %A_ScriptName%
{
WinHIde %A_ScriptName%
Return
}
Else
WinShow,%A_ScriptName%
WinActivate,%A_ScriptName%
ControlFocus,SysListView321,%A_ScriptName%
Return

^#!t::WinHide,%A_ScriptName%

GetActiveWindow:
WinGetActiveTitle, Nookie
If Nookie != %A_ScriptName%
Title = %Nookie%
Return



Use ahk code for tabs, linefeeds. Probably some chars are illegal, I don't know.


Last edited by ribbet.1 on September 28th, 2009, 6:18 am, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 6:24 am 
Offline

Joined: February 20th, 2007, 1:37 pm
Posts: 198
Location: D.C.
And here is one textfile you can use for html tags:

Code:
00NewPage | <DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">{Enter}<HTML>{Enter}<HEAD>{Enter}<TITLE>#</TITLE>{Enter}<META NAME="Generator" CONTENT="TextPad 4.0">{Enter}<META NAME="Author" CONTENT="?">{Enter}<META NAME="Keywords" CONTENT="?">{Enter}<META NAME="Description" CONTENT="?">{Enter}</HEAD>{Enter}{Enter}<BODY bgcolor="FFFFFF" text="000000" link="0033CC" vlink="660066" alink="00CC33">{Enter}{Enter}</BODY>{Enter}</HTML>
00Comment | <!--#-->
Doctype | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
a_link | <a href="??">#</a>
a_name | <a name="??">#</a>
break | <br>
center | <center>#</center>
cite | <cite>#</cite>
code | <code>#</code>
definition | <dfn>#</dfn>
definition list | <dl></dl>
div | <div align="left">#</div>
horizontal rule | <hr>
ordered list | <ol>#</ol>
paragraph | <p>#</p>
preformatted | <pre>#</pre>
blockquote | <blockquote>#</blockquote>
sample output | <sample>#</sample>
unordered list | <ul>#</ul>
font_big | <big>#</big>
font_bold | <b>#</b>
font_emph | <em>#</em>
font _ italic | <i>#</i>
font_small | <small>#</small>
font strong | <strong>#</strong>
font_subscript | <sub>#</sub>
font_superscript | <sup>#</sup>
font_underline | <u>#</u>
font 1 | <font size="1">#</font>
font 2 | <font size="2">#</font>
font 3 | <font size="3">#</font>
font 4 | <font size="4">#</font>
font 5 | <font size="5">#</font>
font 6 | <font size="6">#</font>
font 7 | <font size="7">#</font>
h1 | <h1>#</h1>
h2 | <h2>#</h2>
h3 | <h3>#</h3>
h4 | <h4>#</h4>
h5 | <h5>#</h5>
h6 | <h6>#</h6>
image | <img src="#" alt="?" border="0" height="?" width="?">
table | <table border="1" cellspacing="0" cellpadding="0" width="100%">#</table>
table data | <td>#</td>
table heading | <th>#</th>
table row | <tr>#</tr>
CSS style tag | */#/*


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 28th, 2009, 6:40 am 
Offline

Joined: February 20th, 2007, 1:37 pm
Posts: 198
Location: D.C.
Modified it so the #!T hotkey will toggle the always on top status if you press it twice in succession. I also had to fix the function to send the text in col 2 when you press the {enter} button. Now works as it should. I'm going to update the first post with any latest revision from now on.

You add {enter} {tab} etc. to insert tabs and linefeeds. And you can of course use ahk code for hotkeys to send hotkeys to your word processor. For example, the hotkey shift-F7 centers a line of text in WordPerfect. So if I create a line in my cliptext file like this:
Code:
Exam by Court | {Enter}+{F7}EXAMINATION BY THE COURT

Then I will have that heading typed and centered. OF course any WordPerfect typist no doubt is aware of the awesome macro and scripting capabilities in that word processor, but believe me, PerfectScript enthusiasts, this AHK stuff is even better, and operates in any application.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 16th, 2009, 9:07 am 
Offline

Joined: February 20th, 2007, 1:37 pm
Posts: 198
Location: D.C.
OK, revised yet again. I didn't originally bother to make it copy characters that need escape. So here it is again, with a few improvements.

Code:
#NoEnv
SendMode Input
SetTimer,GetActiveWindow, 30

ButtonLoadFile:  ;;This is where we select the textfile for the tags
Gui Destroy
Gui +OwnDialogs  ; Forces user to dismiss the following dialog before using main window.
FileSelectFile, Nestcepas,, 3, Select a file to read:
if not Nestcepas  ; The user canceled the dialog.
    return
   
; Allow the user to maximize or drag-resize the window:
Gui +Resize

Menu, MyMenu, Add, Load File, ButtonLoadFile
Menu, TargetMenu, Add, Select Target, ButtonSelect_Target
Menu, TargetMenu, Add, DeSelect, Deselect_Target
Menu, MyMenu, Add, Target, :TargetMenu
Gui, Menu, MyMenu


Gui, Add, Button, Hidden Default H0 W0, OK
Gui, Add, ListView, xm r20 w200 vMyListView gMyListView Grid, Name | Text ; r20 w150

LV_ModifyCol()  ; Auto-size each column to fit its contents.

; This is where we get the items from the text file:

FileRead, Durant, %Nestcepas% ;Read file into var Durant

Loop, Parse, Durant, `n, `r ; This should get each tag one at a time
{
   If A_LoopField =
   Continue
   Alpha = %A_Index%
    Will = %A_Loopfield%
   Loop, Parse, Will, |
      {
      If A_Index = 1
      {
         Jersey = %A_LoopField%
         StringReplace,Jersey,Jersey,!,`{!`},All
         StringReplace,Jersey,Jersey,+,`{`+`},All
         StringReplace,Jersey,Jersey,^,`{`^`},All
         Gomer%Alpha% = %Jersey%
         Jersey =
      }
      If A_Index = 2
         {
         Jersey = %A_LoopField%
         StringReplace,Jersey,Jersey,!,`{!`},All
         StringReplace,Jersey,Jersey,+,`{`+`},All
         StringReplace,Jersey,Jersey,^,`{`^`},All
         Goober%Alpha% = %Jersey%
         }
      }
      LV_Add("",Gomer%Alpha%,Goober%Alpha%)
      LV_ModifyCol()  ; Auto-size each column to fit its contents.
      LV_ModifyCol(3, 60) ; Make the Size column at little wider to reveal its header.
;GuiControl, +Redraw, MyListView  ; Re-enable redrawing (it was disabled above).
}
      
; performs alphabetical sort:
LV_ModifyCol(1, "Sort", Name)
Gui, +AlwaysOnTop
Gui, Show
return


DeSelect_Target:
Title =
SetTimer,GetActiveWindow,50
Return


ButtonOK:
GuiControlGet, FocusedControl, FocusV
if FocusedControl <> MyListView
    return
Durham := % LV_GetNext(0, "Focused")
LV_GetText(RowText2, Durham,2)
Goto Gogo



if A_GuiEvent = DoubleClick
Goto MyListView

MyListView:
SetKeyDelay,21,41
DialNine = %Clipboard%
Clipboard =
LV_GetText(RowText2, A_EventInfo,2)  ; Get the text of the second field.
;MsgBox, Rowtext = %Rowtext% `n A_EventInfo = %A_EventInfo%
Gogo:
   WinActivate,%Title%
   Raster := RowText2
   IfInString, Raster, #
      {
      Loop,Parse,Raster, #
         {
         If A_Index = 1
            {
            Defender := A_LoopField
            Send,^x
            ClipWait,.2
            Xevious := Clipboard
            StringReplace,Xevious,Xevious,{, `{`{`},All
            StringReplace,Xevious,Xevious,`}, `{`}`},All
            StringReplace,Xevious,Xevious,{{{}},`{`{`}
            StringReplace,Xevious,Xevious,!, `{!`},All
            StringReplace,Xevious,Xevious,+, `{+`},All
            StringReplace,Xevious,Xevious,^, `{^`},All
            StringReplace,Xevious,Xevious,#, `{#`},All
            ;
            Clipboard =
            }
         Else
            {
            Asteroids := A_LoopField
            }
         }
            Clipboard := % Defender . Xevious . Asteroids
         }
   IfNotInstring, Raster, #
      {
      Clipboard = %Raster%
      }
   SetKeyDelay,-1,-1
   Send,%Clipboard%
   Send,%A_Space%
      Clipboard =
   ;Clipboard = %DialNine%
SetKeyDelay,11,11
Return

GuiSize:  ; Expand or shrink the ListView in response to the user's resizing of the window.
if A_EventInfo = 1  ; The window has been minimized.  No action needed.
    return
; Otherwise, the window has been resized or maximized. Resize the ListView to match.
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 20) ;%
return

GuiClose:  ; When the window is closed, exit the script automatically:
^+#Escape::
ExitApp

Clicky:
ButtonSelect_Target:
MsgBox,After pressing OK, click on the Edit field of the word processor or text editor application you would like to have your text placed in.  If you don't have that application open now, do so before pressing the "OK" button in this message box. (Hint, The Edit field is where the actual document is displayed.)
SetTimer,GetActiveWindow,Off
Title =
KeyWait,LButton,D
MouseGetPos, , , id, control
WinGetTitle, Title, ahk_id %id%
WinGetClass, class, ahk_id %id%
;Msgbox,%Title% is title`n%class% is class
Return

#!t::
WinGetActiveTitle,Title
If Title = %A_ScriptName%
{
WinHIde %A_ScriptName%
Return
}
Else
WinShow,%A_ScriptName%
WinActivate,%A_ScriptName%
ControlFocus,SysListView321,%A_ScriptName%
Return

^#!t::WinHide,%A_ScriptName%

GetActiveWindow:
WinGetActiveTitle, Nookie
If Nookie != %A_ScriptName%
Title = %Nookie%
Return



And as a side note, so far if you select a target (optional) then for a multitabbed editor, the target is specifically the active tab when you selected. So for multitabbed editors I don't really recommend setting a specific target.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: JamixZol and 6 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