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 

Keyfficiency

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
airjrdn



Joined: 25 Feb 2008
Posts: 35

PostPosted: Tue Apr 22, 2008 10:28 pm    Post subject: Keyfficiency Reply with quote

I'm still very new to AutoHotkey, but it's easy to see how powerful it can be. I started putting together a script that replaced multiple single-purpose executables I always had running. I called it Keyfficiency, here's what it does:

Quote:

Moving Windows:
---Use Winkey + Numpad keys to move windows to screen edges (requires numlock on)

Macros:
---F6 to toggle Macro recording on/off (F7 for playback)

Automatic Text Replacement:
---Modify Triggers.ini

Plain Paste
---Win + v to paste unformatted text from clipboard

Clipboard/Text saving & retrieving
---Win + c to save an item
---Win + space to show list of saved items for pasting
------Shift click an item in the list to delete it (with confirmation)
------Ctrl click an item in the list to edit it


A link to the compiled exe, with icons and source code is here.

Here's the latest sourcecode:
Code:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Language:       English
;   Platform:       Win32 (XP tested)
;   Author:         Bill Minton <bill@themintonfamily.com>
;   Version:        1.0
;   Usage:          The goal of this script is to make people more efficient
;                   by implementing the following features:
;
;
;                   Moving Windows:
;                       Use Winkey + Numpad keys to move windows to screen edges (requires numlock on)
;
;                   Macros:
;                       F6 to toggle Macro recording on/off (F7 for playback)
;
;                   Automatic Text Replacement:
;                       Modify Triggers.ini
;
;                   Plain Paste
;                       Win + v to paste unformaated text from clipboard
;
;                   Clipboard/Text saving & retrieving
;                       Win + c to save an item
;                       Win + space to show list of saved items for pasting
;                           Shift click an item in the list to delete it (with confirmation)
;                           Ctrl click an item in the list to edit it
;
;
;
;   This script includes modified code from:
;       Rajat       at http://www.autohotkey.com/forum/viewtopic.php?t=86
;       Laszlo      at http://www.autohotkey.com/forum/viewtopic.php?t=11427
;       kiu         at http://www.autohotkey.com/forum/topic7887.html
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#Persistent
#SingleInstance force
AutoTrim Off
Menu tray, icon, Disabled.ico
bRecording = 0
sMacro := ""
ShiftState := "U"
ControlState := "U"
AltState := "U"
uInput := ""

; add menu items
    menu, tray, NoStandard
    Menu,Tray,Add,&Reload Triggers.ini,LOAD
    Menu,Tray,Add,&About, About
    menu, tray, add, Exit,exitapplication

; create directories
    IfNotExist, data
        FileCreateDir, data

    IfNotExist, data\saved
        FileCreateDir, data\saved

;    SetBatchLines, 10ms
    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 ++
    }

    ; QuickMacro                                                                - modified version of script from Rajat at http://www.autohotkey.com/forum/viewtopic.php?t=86
            Loop
            {
               Input, UserInput, L1 V,{F6}, %Triggers%

                uInput = %uInput%%UserInput%
                sHS = %sHS%%UserInput%

                if bRecording = 1
                {
                    ;MsgBox "Adding to sMacro " %UserInput%
                    HandleKeyStates()
                    if UserInput != %A_Tab%
                        sMacro = %sMacro%%UserInput%
                }
                else
                {
                    Loop, %Trigger0%
                    {
                        IfEqual, A_Index, 1, Continue
                        StringTrimRight, CT, Trigger%A_Index%, 0
                        IfInString, uInput, %CT%
                        {
                            StringLen, Tlen, CT
                            IniRead, ToSend, %a_scriptdir%\Triggers.ini, Triggers, %CT%
                            StringReplace, ToSend, ToSend, <s>, %a_space%, A
                            IfNotEqual, ToSend, ERROR, SendInput, {BS %Tlen%}%ToSend%
                            uInput := ""
                            Break
                        }
                    }
                }
            }

            F6::  ;MsgBox "Pressed F6"
                if bRecording = 0
                {
                    Menu tray, icon, Record.ico
                    bRecording = 1
                    sMacro := ""
                }
                else
                {
                    Menu tray, icon, Play.ico
                    bRecording = 0
                    ShiftState := "U"
                    ControlState := "U"
                    AltState := "U"
                }
            Return
       
            F7::
                SendInput %sMacro%
            Return
       
            ~+F7::
                MsgBox %sMacro%
            Return
       
            ~+Up::
            ~+Down::
            ~+Left::
            ~+Right::
            ~+Home::
            ~+End::
            ~+Backspace::
            ~+Delete::
            ~+PgUp::
            ~+PgDn::
            ~+Insert::
            ~+Tab::
            ~Up::
            ~Down::
            ~Left::
            ~Right::
            ~Home::
            ~End::
            ~Backspace::
            ~Delete::
            ~PgUp::
            ~PgDn::
            ~Tab::
            ~Insert::
            ~^Up::
            ~^Down::
            ~^Left::
            ~^Right::
            ~^Home::
            ~^End::
            ~^Backspace::
            ~^Delete::
            ~^PgUp::
            ~^PgDn::
            ~^Tab::
            ~^Insert::
            ~+^Up::
            ~+^Down::
            ~+^Left::
            ~+^Right::
            ~+^Home::
            ~+^End::
            ~+^Backspace::
            ~+^Delete::
            ~+^PgUp::
            ~+^PgDn::
            ~+^Tab::
            ~+^Insert::
            ~F2::
            ~F3::
            ~F4::
                if bRecording = 1
                {
                    keyPressed = %A_ThisHotKey%
                    HandleKeyStates()
                    StringReplace, keyPressed, keyPressed, +, , All
                    StringReplace, keyPressed, keyPressed, ~, , All
                    StringReplace, keyPressed, keyPressed, ^, , All
                    sMacro = %sMacro%{%keyPressed%}
                    ;msgbox >%sMacro%<
                    ;msgbox >%keyPressed%<
                }
            Return
       
        HandleKeyStates()
        {
            global
       
            GetKeyState, sstate, Shift
            if ShiftState != %sstate%
                if sstate = D
                    sMacro = %sMacro%{shift down}
                else
                    sMacro = %sMacro%{shift up}
            ShiftState = %sstate%
       
            GetKeyState, cstate, Control
            if ControlState != %cstate%
                if cstate = D
                    sMacro = %sMacro%{ctrl down}
                else
                    sMacro = %sMacro%{ctrl up}
            ControlState = %cstate%
       
            GetKeyState, astate, Alt
            if AltState != %astate%
                if astate = D
                    sMacro = %sMacro%{alt down}
                else
                    sMacro = %sMacro%{alt up}
            AltState = %astate%
        }

    ; WinMove
        #Numpad1::
            MoveWin("LB")
        return
   
        #Numpad2::
            MoveWin("MB")
        return
   
        #Numpad3::
            MoveWin("RB")
        return
   
        #Numpad4::
            MoveWin("LM")
        return
   
        #Numpad5::
            MoveWin("MM")
        return
   
        #Numpad6::
            MoveWin("RM")
        return
   
        #Numpad7::
            MoveWin("LT")
        return
   
        #Numpad8::
            MoveWin("MT")
        return
   
        #Numpad9::
            MoveWin("RT")
        return
   
   
    MoveWin(MoveToPosition)
    {
        WinGetActiveTitle, Title
        SysGet, m, MonitorWorkArea
        WinGetPos, , , w, h, A  ; "A" to get the active window's pos.
   
        if InStr(MoveToPosition, "LB") > 0
        {
            x := 0
            y := mBottom - h
        }
   
        if InStr(MoveToPosition, "MB") > 0
        {
            x := (mRight / 2) - (w / 2)
            y := mBottom - h
        }
   
        if InStr(MoveToPosition, "RB") > 0
        {
            x := mRight - w
            y := mBottom - h
        }
   
        if InStr(MoveToPosition, "LM") > 0
        {
            x := 0
            y := (mBottom / 2) - (h / 2)
        }
   
        if InStr(MoveToPosition, "MM") > 0
        {
            x := (mRight / 2) - (w / 2)
            y := (mBottom / 2) - (h / 2)
        }
   
        if InStr(MoveToPosition, "RM") > 0
        {
            x := mRight - w
            y := (mBottom / 2) - (h / 2)
        }
   
        if InStr(MoveToPosition, "LT") > 0
        {
            x := 0
            y := 0
        }
   
        if InStr(MoveToPosition, "MT") > 0
        {
            x := (mRight / 2) - (w / 2)
            y := 0
        }
   
        if InStr(MoveToPosition, "RT") > 0
        {
            x := mRight - w
            y := 0
        }
   
        WinMove, %Title%,, %x%, %y%
    }

   LOAD:
      Reload
    Return

    ; Plain Paste (remove formatting from clipboard & paste) - WinKey + v       - modified version of script from Laszlo at http://www.autohotkey.com/forum/viewtopic.php?t=11427
        #v::                            ; Text–only paste from ClipBoard
           Clip0 = %ClipBoardAll%
           ClipBoard = %ClipBoard%       ; Convert to text
           ;SendInput %ClipBoard%         ; For best compatibility: SendPlay
           Send,^v
           Sleep 50                      ; Don't change clipboard while it is pasted! (Sleep > 0)
           ClipBoard = %Clip0%           ; Restore original ClipBoard
           VarSetCapacity(Clip0, 0)      ; Free memory
        Return
   
; clipboard utility (saved items, etc.)                                         - modified version of script from kiu at http://www.autohotkey.com/forum/topic7887.html
        ; Win + Space - display menu
            #Space::
                Menu,kiuSaved,add,Dummy,Cancel
                Menu,kiuSaved,deleteAll
                Loop,data\saved\*.txt
                {
                    idx = %A_Index%
                    if idx < 10
                        zero=0
                    else
                        zero=
                    Menu,kiuSaved,add,%zero%%A_Index%. %A_LoopFileName%,clipSaved
                }
                Menu,kiu,add,Saved Clips, :kiuSaved
                Menu,kiu,add,Cancel,Cancel
                Menu,kiu,show
   
            return
   
        ; Win + c - save text
            #c::
                InputBox, name, Name of the clip, Select the name for the clip
                if ErrorLevel = 0
                {
                    clipboard=
                    Send ^c
                    ClipWait
                    clipText = %clipboard%
                    FileAppend, %clipText%, data\saved\%name%.txt
                }
                return
   
        Cancel:
        return   
   
        clipSaved:
            StringTrimLeft, OutputVar, A_ThisMenuItem, 4
   
            if(GetKeyState("CTRL" , "P"))
                Run,data\saved\%OutputVar%
            else
            {
                if(GetKeyState("Shift" , "P"))
                {
                    MsgBox, 4, , Are you sure you want to delete %OutputVar%?
                    IfMsgBox Yes
                    {
                        FileDelete, data\saved\%OutputVar%
                    }
                }
                else
                {
                    FileRead, clip, data\saved\%OutputVar%
                    clipboard=
                    clipboard=%clip%
                    Send,^v
                }
            }
            return

    exitapplication:
        FileDelete, data\*.txt
        exitapp
        return

About:
msgbox,
(
Moving Windows:
     Use Winkey + Numpad keys to move windows to screen edges

Macros:
     F6 to toggle Macro recording on/off (F7 for playback)

Automatic Text Replacement:
     Modify Triggers.ini

Plain Paste
    Win + v to paste unformaated text from clipboard

Clipboard/Text saving & retrieving
     Win + c to save an item
     Win + space to show list of saved items for pasting
          Shift click an item in the list to delete it (with confirmation)
          Ctrl click an item in the list to edit it
)
Return


Feel free to offer suggestions and code enhancements, and thank you to others who have posted their code. Hopefully others will find this useful.
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
Page 1 of 1

 
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