Posts tagged ‘Autohotkey’

Creating menus with Autohotkey

Here’s a simple example how to create a menu with Autohotkey, in this case it allows the user to select one of the LaTeX standard environments itemize, enumerate or description when Alt-y is pressed.

!y::
Gui, 1:Destroy
Gui, Add, Text,, Please enter the environment:
Gui, Add, DDL, vList, itemize||enumerate|description
Gui, Add, Button, Default, Input
Gui, Show
return

ButtonInput:
Gui, Submit, NoHide
Gui, 1:Destroy
Send %List%
return

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

AHK Datei für meinen DTK-Artikel

Hier ist der Inhalt meiner AHK-Datei für den Artikel in der TeXnischen Komödie:

#IfWinActive ahk_class QWidget
{
^k:: 
Send {HOME}
Send {SHIFT}+{END}
Send {DEL 2}
return

^d::
Send {HOME}
Send {SHIFT}+{END}
Send ^c
ClipWait, 2
Send {END}
Send {ENTER}
Send ^v
return
}
#IfWinActive 

:*:ch#::\chapter{{}{}}{LEFT}
:*:s#::\section{{}{}}{LEFT}
:*:ss#::\subsection{{}{}}{LEFT}
:*:sss#::\subsubsection{{}{}}{LEFT}

:*:b#::\begin{{}{}}{LEFT}
:*:e#::\end{{}{}}{LEFT}

:*:bf#::\textbf{{}{}}{LEFT}
:*:tt#::\texttt{{}{}}{LEFT}
:*:it#::\textit{{}{}}{LEFT}

:*:desc#::\begin{{}description{}}`r\item[]`r\item[]`r\item[]`r\end{{}description{}}{UP 3}{LEFT}
:*:enum#::\begin{{}enumerate{}}`r\item `r\item `r\item `r\end{{}enumerate{}}{UP 3}
:*:item#::\begin{{}itemize{}}`r\item `r\item `r\item `r\end{{}itemize{}}{UP 3}

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Creating LaTeX environments with Autohotkey the easy way

Here’s a neat little script (bound to Alt-e) which requests an environment name from the user. If the entered string has e.g. the form "itemize3" it creates

\begin{itemize}
\item
\item 
\item 
end{itemize} 

and puts the cursor directly after the first \item.

If the entered string includes no number at the end (e.g. „itemize“), just the environment is created.

!e::
InputBox, UserEnv, Environment, Please enter an environment!, , 240, 120
If ErrorLevel
	return
Else 
if( RegExMatch(UserEnv, "(.*?)(\d+)$", splitted) ) {
	Send \begin{{}%splitted1%{}}{Enter}
		Loop %splitted2% {
			Send \item {Enter}
		}
	Send \end{{}%splitted1%{}}{Up}
	count2 := splitted2 - 1 
	Loop %count2% {
		Send {Up}
	}			
} 
Else 
	Send \begin{{}%UserEnv%{}}{Enter 2}\end{{}%UserEnv%{}}{Up}
return

Thx to MCL for providing help with the regexp!

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Deleting complete lines in TeXworks / ganze Zeilen löschen in TeXworks

What I really like in Emacs is the Ctrl+k key combination to delete the rest of the line. As I wanted this feature in TeXworks as well, where I usually set the cursor to the beginning of the line anyway I decided to implement a little Autohotkey script to do this. As I do not want this script to overwrite Emacs‘ own Ctrl-k I check if the window is an instance of the ‚QWidget‘ class (check with Autohotkey’s WindowSpy).

#IfWinActive ahk_class QWidget
^k::
Send {home}
Send {Shift}+{End}
Send {Del 2}
return

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Equipping TeXworks with a ‚duplicate this line‘ feature / Zeilen duplizieren in TeXworks

I really like TeXworks but miss some of the functions other editors provide. Notepad++ for example has a nice „duplicate this line“ feature available via Ctrl+D that I’d like to use in TeXworks as well. Thanks to Autohotkey this is quite simple (also thanks to the posting from www.autohotkey.com/board/topic/19002-duplicate-line/)

^d::
SetKeyDelay, -1
Temp := ClipboardAll
Clipboard = 
Send {home}
Send {Shift}+{End}^c
ClipWait, 2
Send {End}{Enter}
SendRaw %Clipboard%
Clipboard := Temp
return

PS: I guess TeXworks can do this via the built-in scripting but I never played with that. If one of my readers has a proposal, please send it to me.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Modifying selected text with Autohotkey

Autohotkey is an amazing tool to define hotkeys such as s# that get automatically expanded to \section{}. On earlier occasions I had already written some blog posts on this topic. Today (encouraged by a question on tex.stackexchange) I managed to compile a short script, which takes some selected text, inserts a specific command and pastes the selected text again. Quite helpful if one want’s to define a shortcut to e.g. make the selected text bold.

F4::
Send ^c
Send \command{{}{}}{LEFT}
Send ^v
Return

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Autohotkey: Wie man die CapsLock Taste abschaltet

Hier ein hilfreicher Tipp, wie man die dusselige CapsLock Taste ihrer absolut nicht mehr zeitgemäßen Funktion berauben kann. In das Autohotkey File einfach folgenden Abschnitt eintragen:

SetCapsLockState, alwaysoff 

Wer nicht weiß, was Autohotkey ist, nutze die Suche im Blog.

Gefunden unter http://www.autohotkey.com/community/viewtopic.php?t=55412. Alternativ geht es auch so:

CapsLock::      ; CapsLock
+CapsLock::   ; Shift+CapsLock
!CapsLock::   ; Alt+CapsLock
^CapsLock::      ; Ctrl+CapsLock
#CapsLock::      ; Win+CapsLock
^!CapsLock::   ; Ctrl+Alt+CapsLock
^!#CapsLock::   ; Ctrl+Alt+Win+CapsLock
return         ; Do nothing, return

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Schneller TeXen mit Autohotkey, Autokey, Textexpander & Co – Teil 4

Bevor wir zum Textexpander unter Mac OS kommen, möchte ich noch ein interessantes Feature von Autokey vorstellen. Für die einzelnen Phrasen-Unterordner lassen sich selbst Kürzel definieren. In dem folgenden Beispiel habe ich die Menü Taste genutzt, die hier auf meinem Notebook zu finden ist.

Drücke ich diese Taste, so wird ein Menü mit den Inhalten des Ordners angezeigt und ich kann einen Eintrag auswählen.

Über den Schalter „Show in Tray menu“ wird gesteuert, ob dieses Kürzel auch im Menü von Autokey angezeigt werden soll.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Schneller TeXen mit Autohotkey, Autokey, Textexpander & Co – Teil 2

Im heutigen Artikel möchte ich Autokey vorstellen, das ich unter Ubuntu 11.10 benutze und das auch zumindest die von mir genutzten Autohotkey-Funktionen abdeckt.

Installation

Über sudo apt-get install autokey kann man zwar Autokey installieren, ich bevorzuge jedoch die ppa-Version, da diese unter Umständen aktueller ist.

Was muss man dafür tun? Nicht viel:

sudo add-apt-repository ppa:cdekter/ppa
sudo apt-get update
sudo apt-get install autokey

Ein Hinweis: Nach der Installation taucht das autokey eventuell nicht in der Unity Oberfläche auf, obwohl der Prozess im Hintergrund läuft. In diesem Fall drücken, dann sollte das Menü angezeigt werden. Unter Ubuntu 11.10 hatte ich zusätzlich das Problem, dass autokey die Einstellung zum automatischen Start nicht speichern wollte, weil der Pfad /home/uwe/.config/autostart/ fehlte, die manuelle Ordneranlage half in diesem Fall.

Im nächsten Teil dann mehr zur Bedienung von Autokey.

Nachtrag vom 28.06.2012: http://maketecheasier.com/make-autokey-works-in-ubuntu-natty/2011/06/26 erklärt, wie man Autokey auch unter Unity zum Laufen bekommt.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Schneller TeXen mit Autohotkey, Autokey, Textexpander & Co – Teil 1

In zwei kurzen Beiträgen hatte ich bereits Tools vorgestellt, die Tastaturkürzel in komplette Textteile expandieren [1] [2]. Auch wenn viele Editoren geeignete Shortcuts mitbringen, sehe ich persönlich noch immer eine immense Zeitersparnis beim Einsatz dieser Shortkey-Expander. Heute möchte ich auf mein aktuelles Setup mit Autohotkey eingehen, in weiteren Teilen stelle ich dann Autokey für Linux und Textexpander für den Mac vor.

Die Installation von Autohotkey [3] ist ziemlich einfach. Beim ersten Start bietet das Tool an, eine entsprechende .ahk Datei anzulegen. Meine .ahk Datei habe ich im Dropbox-Ordner abgelegt und lediglich eine Verknüpfung zu dieser Datei im Autostart-Ordner angelegt. Vorteil ist, dass dadurch sowohl auf meinem Desktop als auch auf meinem Laptop immer die aktuellste Version verfügbar ist.

Schauen wir uns mal einige Definitionen an. Die ersten Kürzel, die ich definiert habe, waren die für die Eingabe von Dokumentstrukturen.

:*:s#::\section{{}{}}{LEFT}
:*:ss#::\subsection{{}{}}{LEFT}
:*:sss#::\subsubsection{{}{}}{LEFT}

Die Syntax bedeutet: Wann immer der User s# drückt, füge ein \section{} in den Text ein und gehe ein Zeichen nach links. Die geschweiften Klammern der \section Befehle müssen dabei escaped werden, da geschweifte Klammern in Autohotkey selbst aktive Zeichen sind.

Da es in den meisten Dokumenten auch einen standardmäßigen Satz an Klassen- und Paketdefinitionen gibt, lassen sich diese auch wunderbar per Kürzel definieren:

:*:doc#::\documentclass{{}scrartcl{}}`r`r\begin{{}document{}}`r`r`r\end{{}document{}}
:*:st#::\usepackage[utf8]{{}inputenc{}}`r\usepackage[T1]{{}fontenc{}}`r\usepackage{{}booktabs{}}`r
:*:u#::\usepackage[]{{}{}}{LEFT}

Da zu einer öffnenden Klammer auch in 99,99% der Fälle auch die schließende Klammer gehört, lässt sich hier auch ein Shortcut definieren, die pro Nutzung zwei Tastendrücke spart:

:*:(::(){LEFT}
:*:{::{{}{}}{LEFT}
:*:[::[]{LEFT}

Erhebliches Einsparpotential bieten auch Kürzel für die Textauszeichnung, \begin{}/\end{} und die verschiedenen Aufzählungen:

:*:bf#::\textbf{{}{}}{LEFT}
:*:it#::\textit{{}{}}{LEFT}
:*:tt#::\texttt{{}{}}{LEFT}

:*:b#::\begin{{}{}}{LEFT}
:*:e#::\end{{}{}}{LEFT}

:*:desc#::\begin{{}description{}}`r\item[]`r\item[]`r\item[]`r\end{{}description{}}{UP 3}{LEFT}
:*:enum#::\begin{{}enumerate{}}`r\item `r\item `r\item `r\end{{}enumerate{}}{UP 3}
:*:item#::\begin{{}itemize{}}`r\item `r\item `r\item `r\end{{}itemize{}}{UP 3}
:*:i#::\item{Space}
:*:di#::\item[]{LEFT}

Da sich mit Autohotkey auch einfache Datumsberechnungen ausführen lassen und ich einige Male am Tag das aktuelle oder gestrige Datum benötige, habe ich diese auch als Kürzel abgelegt.

:*:g#::
   Gestern = %A_Now%
   EnvAdd, Gestern, -1, Days
   FormatTime, Gestern, %Gestern%, dd.MM.yyyy
   Send, %Gestern%
   Return
:*:ä#::
   Heute = %A_Now%
   FormatTime, Heute, %Heute%, dd.MM.yyyy
   Send, %Heute%
   Return
:*:m#::
   Morgen = %A_Now%
   EnvAdd, Morgen, 1, Days
   FormatTime, Morgen, %Morgen%, dd.MM.yyyy
   Send, %Morgen%
Return

Im nächsten Teil geht es dann darum, wie sich diese Kürzel unter Linux definieren lassen.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website