Keyboard shortcuts for Lectora
June 7, 2005 12:00 AM
Alright, here goes.To install:1) Download and install www.autohotkey.com. 2) Create two files that contain the Autohotkey script as shown further down in this message3) Create a Windows shortcut that executes "autohotkey Lectora.ahk" (you will have to include directory paths here of course). Now the hotkeys are activate, a taskbar icon is present in Windows' taskbarExample usage scenario (based on Lectora 2005, scripts were not tested on later versions)1) Start Lectora and open one of your titles2) Make sure in the tree view showing your course structure, icons are visible in front of each line (the script needs this to find lines of a certain type)3) Use your mouse and click in the page view4) Press ESC. Script has now moved the focus to the tree view.5) Press Up and Down a few times and by doing this, select a random page6) Press Enter. The script now changes the page for you7) press Down a few times until you select an element on this page, then press Enter. The script now opens the properties dialog for this page element.8) With focus still in the tree view, press Ins. The script now inserts a new page and moves the mouse to click its name, which means you can start typing directly to choose the new page's name9) Press Del and the script will delete the page (difference with standard Lectora is that the next page is automatically selected so you can press Del a few times to delete multiple pages/items.10) Press shift-i, you can now choose a directory (that contains images, paths are hardcoded in the script) and then insert an image from this directory on your page.11) Read the comments in the two script files for any other possibilities I did not include.Enjoy.Oh, two more things:1) the script also autosaves your Lectora title every 10 minutes. This only works if Lectora is the active window and you don't have a dialog open.2) Autohotkey works by simulating your keyboard and mouse. I think I have blocked user input when the script is performing a task, but to be on the safe side you should not move your mouse or use your keyboard when the script is performing a task like inserting a new page.File 1 - "Lectora.ahk";Test ; AutoHotkey Version: 1.x; Language: English; Platform: Win9x/NT; Author: A.N.Other ;; Script Function:; Template AutoHotkey script.;#include LectoraKeys.ahk;============= RememberMousePos ================; Stores the current mouse position; by default, relative to the screen ;
; Some global variables are neededPrevMousePosX = 0PrevMousePosY = 0RememberMousePos(coords){ global PrevMousePosX, PrevMousePosY mouseCoordMode := Relative if (coords = "Screen") { mouseCoordMode := "Screen" } CoordMode Mouse, %mouseCoordMode% MouseGetPos PrevMousePosX, PrevMousePosY ; store current mouse CoordMode Mouse, Relative};============= RestoreMousePos ================; Puts the mouse back in its stored place; It will remember the X, Y and also the mode; (relative, screen) ;
RestoreMousePos(){ global PrevMousePosX, PrevMousePosY CoordMode Mouse, %mouseCoordMode% MouseMove PrevMousePosX, PrevMousePosY,0 ; store current mouse CoordMode Mouse, Relative};============= RememberWorkingDir ================; Stores the current working dir ;
; Some global variables are neededprevWorkingDir := ""RememberWorkingDir(){ global prevWorkingDir prevWorkingDir := A_WorkingDir};============= RestoreWorkingDir ================; Puts the previous value of working dir back ;
RestoreWorkingDir(){ global prevWorkingDir SetWorkingDir %prevWorkingDir%};=============== CenterWindow =============; Center a window on the active screen;
CenterWindow(){ RememberMousePos("screen") SysGet NrMonitors, MonitorCount If (NrMonitors = 1) { ; No action needed if only one monitor used return } MouseClick Left, 30, 5, , 0 ; Get window ID of active window MouseGetPos X, Y, WinID SysGet MonArea, Monitor, 1 WinGetPos X, Y, WinWidth, WinHeight, ahk_id %WinID% ; get size of window NewX := MonAreaLeft + ((MonAreaRight - MonAreaLeft) / 2) - ( WinWidth / 2) NewY := ((MonAreaBottom - MonAreaTop) / 2) - ( WinHeight / 2) WinMove ahk_id %WinID%, , %NewX%, %NewY% ; move window RestoreMousePos()}File 2 - "LectoraKeys.ahk";; Autosave Lectora every 10 minutesSetTimer LectoraAutoSave, 600000 ;=========================================================== =========;======================= Current short cuts =========================;;; Only in tree-view;
;; shift-A - insert action; shift-L - Insert library object (including switch to library ; undefined F2 undefined Ctrl-5 - In text box: insert a line with 5 pt space; Everywhere else;
;; Ins undefined F12 undefined Sh-F12 - Publish to HTML (changes only);;======================= Other functionality ========================;; Auto save - every 10 minutes, when Lectora is active window;;======================= Other functionality ========================;; 1) Please make sure icons are visible in the tree view.; The keyboard shortcuts need this. ;
;
; Explanation;; Del undefined x1) - 'Enter' also captured when in main menu; 2) - 'Ins', add 'click on icon before doing add page, because sometimes a tree item selected but; the menu options isn't enabled (however the toolbar is, but you can't rely on its location); x3) - It seems that sometimes the tree view's id is SysTreeView322 (instead of ...321 which is used; in this file. No idea why, but check this a few times to try to understand what happens); x4) - If you play a movie in a page, press F11 and return to the edit mode, SysTreeView 321; becomes SysTreeView322. Need to look into this.; 5) - ESC doesn't close a context menu; 6) - When pressing shift-I after using cursor to go to another page (and the page isn't selected); yet, an image is not inserted. Solution: always selected page as well.; Note: the selection in the tree view is grayed while the page is buildingLectoraActive(){ IfWinActive Lectora { ; Next check: should not be in menu bar. Can be checked by looking at status bar ; Statusbar is "Ready" when not in menu StatusBarGetText statusText, Lectora StringLeft statusBegin, statusText, 5 if (statusBegin == "Ready") {undefined return false } } else return false}CaptivateActive(){ IfWinActive Macromedia Captivate { return true } else return false}InTreeView(){ ControlGetFocus currCtrl, Lectora StringLeft currCtrl, currCtrl, 11 if (currCtrl = "SysTreeView") return true else return false};============= FindSelectedTreeItem ================; Uses the blue color of a selection to locate the; selected item in the tree view and returns its x, y; coordinates ;
FindSelectedTreeItem(ByRef x,ByRef y){ ControlFocus SysTreeView321, A ControlGetPos TreeX, TreeY, TreeWidth, TreeHeight, SysTreeView321, A Sleep 100 PixelSearch x, y, TreeX, TreeY, % TreeX+TreeWidth, % TreeY+TreeHeight, 0xC56A31, 0, Fast; if (x = "") ; undefined
FocusTreeView(){ ControlFocus SysTreeView322, A ControlGetFocus focusedCtrl, A if (focusedCtrl <> "SysTreeView322") { ControlFocus SysTreeView321, A } Sleep 200};============= Get Selection Coords ================; Find the pixel coordinates of the currently; selected item in the tree view ;
GetSelectionCoords(ByRef paramX,ByRef paramY){ ControlGetPos TreeX, TreeY, TreeWidth, TreeHeight, SysTreeView322, A if (TreeX = "") { ; Apparently the other name for the tree view is in use ControlGetPos TreeX, TreeY, TreeWidth, TreeHeight, SysTreeView321, A } PixelSearch x, y, TreeX, TreeY, TreeX+TreeWidth, TreeY+TreeHeight, 0xC56A31, 0, Fast paramX = %x%; paramY = %y%;};================== shift-Space == Insert small line ===================; Sometimes you want to insert a small line. This means putting in a; space with font size 5; This hotkey makes this easier ;
$^5::if not LectoraActive(){ Send ^5 return}Send {Home}{Space}{ShiftDown}{Left}{ShiftUp}ControlFocus ComboBox2Send 5{Return}{Return}return;================== shift-A == Insert action ================$+a::; Lectora should be active application and in tree viewif not LectoraActive() or not InTreeView(){ GetKeyState state, CapsLock, T if state = D Send a else Send A return}Send !a{Down 5}{NumPadEnter}return ;
;================== shift-L == Insert library object ================$+l::; Lectora should be active application and in tree viewif not LectoraActive() or not InTreeView(){ Send L return}Send !t{Down}{Down}{Down}{Down}{Down}{Right}{Down}{NUmPadEnter}Sleep 250IfWinActive Open{ Send h:TrainingMaterialsCBTGalleryLectora{Enter} Send +{Tab}{Down}{Up}}return ;
;================== shift-I == Insert image =========================$+i::; Lectora should be active application; If in tree view, the dialog will be started; If not in tree view, but image dialog open, directory gui is shown;if not LectoraActive() or not InTreeView();{ ;Send I ;return;}if LectoraActive() and InTreeView(){ ; Selected item in tree view should be a page ; Choose 'add image' from the menu Send !a{Up}{Up}{Up}{Up}{Up}{Right}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{NU mPadEnter} Sleep 250 IfWinActive Image { Sleep 100 Send {Tab}{Tab}{Enter}undefined Click on 'Import' button Sleep 250 ; Send h:TrainingMaterialsCBTGalleryLectora{Enter} ; Send +{Tab}{Down}{Up} } Gui Add, Text,, Select a location Gui Add, Listbox, vDirChoice Choose2 AltSubmit, 1 - Default|2 - LP Images Gui Add, Button, default, OK Gui Add, Button, X+10, Cancel Gui Show,,Select a location; CenterWindow() return}IfWinActive Add an image{ Gui Add, Text,, Select a location Gui Add, Listbox, vDirChoice Choose2 AltSubmit, 1 - Default|2 - LP Images Gui Add, Button, default, OK Gui Add, Button, X+10, Cancel Gui Show,,Select a location; CenterWindow() return}; If none of the above optionsSend IreturnButtonOK:Gui SubmitGui Destroyif DirChoice = 1 newDir = H:TrainingMaterialsCBTGalleryLectoraif DirChoice = 2 newDir = H:Quintiq On DemandLogisticsPlannerImagesif newDir <> ""{ Send !n Sleep 250 Send %newDir% Send {Enter} Send +{Tab}{Down}{Up}}returnGuiEscape:Gui Destroyreturn ;
$Ins::; Lectora should be active applicationif not LectoraActive(){ Send {Ins} return}RememberMousePos(Screen)FocusTreeView()FindSelectedTreeItem(x,y)undefined Make sure current page is selectedMouseClick left, x - 10, y + 5, ,0Loop 12undefined make sure page switch is completed{ Sleep 250 FindSelectedTreeItem(x,y) if (x <> "") break}Send !a{Down}{Down}{Down}{Return} ; from menu, insert new pageSleep 250FocusTreeView()FindSelectedTreeItem(x,y) ; locate selected item (newly created page)MouseClick left, X-5, Y+5, , 0undefinedMouseMove PrevX, PrevY, 0Sleep 250MouseClick left, x+20, y+5, , 0RestoreMousePos()return$Del::; Lectora should be active application and in tree viewif not LectoraActive() or not InTreeView(){ Send {Del} return}MouseGetPos PrevX, PrevYundefined locate selected item (newly created page)MouseClick left, X-5, Y+5, , 0undefined click twice, to activate 'rename'Send {Del}Sleep 300ControlFocus SysTreeView321, AMouseMove PrevX, PrevY, 0undefined Should be in edit mode (checked via window coords)WinGetPos WinX, WinY, 0, 0if (WinX = 0 and WinY = 0){ Send {Esc} return}MouseGetPos PrevX, PrevYundefinedMouseClick left, 7, 102, , 0undefinedMouseMove PrevX, PrevY, 0undefined
$F2::if not LectoraActive() or not InTreeView(){ Send {F2} return}ControlGetPos TreeX, TreeY, TreeWidth, TreeHeight, SysTreeView321, APixelSearch x, y, TreeX, TreeY, TreeX+TreeWidth, TreeY+TreeHeight, 0xC56A31, 0, FastMouseGetPos PrevX, PrevYMouseClick left, X-10, Y+5, , 0MouseClick left, x+20, y+5, , 0MouseMove PrevX, PrevY, 0return;================== Enter == Open selected item/page ================$Enter::if not LectoraActive() or not InTreeView(){ Send {Enter} return}GetSelectionCoords(TreeX, TreeY)CoordMode Mouse, ScreenMouseGetPos PrevX, PrevYCoordMode Mouse, RelativeCheckPixelX = %TreeX%CheckPixelX -= 11CheckPixelY = %TreeY%CheckPixelY += 7PixelGetColor clr, CheckPixelX, CheckPixelY ; Check color of iconTreeX -= 5TreeY += 5/** Checks to see whether I can handle different DPIsSysGet, cxborder, 5SysGet, cyborder, 6MsgBox %cxborder%-%cyborder%; cxborder 1 1SysGet, cxborder, 45SysGet, cyborder, 46MsgBox 45-%cxborder%-%cyborder%; 3d border 2 2SysGet, cxborder, 7SysGet, cyborder, 8MsgBox 7-%cxborder%-%cyborder%; fixed frame 3 3SysGet, cxborder, 83SysGet, cyborder, 84MsgBox 83-%cxborder%-%cyborder%; focus border 1 - 1SysGet, cxborder, 30SysGet, cyborder, 31MsgBox 30-%cxborder%-%cyborder%; title bar 31-31SysGet, cxborder, 32SysGet, cyborder, 33MsgBox 32-%cxborder%-%cyborder%; sizing border 4 4*/if (clr = "0x000000"){ ; Selected item is an item on a page TreeX -= 2 MouseClick left, TreeX, TreeY, ,0 Sleep 250 MouseClick left, TreeX, TreeY, ,0 CoordMode Mouse, Screen MouseMove PrevX, PrevY, 0 CoordMode Mouse, Relative}else{ MouseClick left, TreeX, TreeY, ,0 CoordMode Mouse, Screen MouseMove PrevX, PrevY, 0 CoordMode Mouse, Relative}return ;
Lectora_PublishToHtml(publishAll){ KeyWait Shift BlockInput On ; Choose 'publish to HTML' from menu Send !p MouseClick left, 340, 100 ; Click on option Publish to HTML ; Lectora starts checking, keep pressing the 'Publish' ; button until checking is done ; Just in case, let's not loop longer than 10 seconds (currently equal to ; 40 cycles) ; PublishTimeOut := true loop 40 { Sleep 125 MouseClick left, 100, 360 ; the Done or Publish button Sleep 125 ; a window 'unused resources' could pop up ; IfWinExist, Remove Resource From Title {undefined MouseClick left, 275, 140 ; Don't remove buttonundefined Sleep 250 } ; 2 things can happen: (1) publishing starts, or (2) publish window ; disappears which means errors occurred) ; Start publishing ; ifWinExist, Publish HTML Location {undefined MouseClick left, 61, 167undefined MouseClick left, 59, 146undefined MouseClick left, 240, 400 ; Click OKundefined Sleep 250undefined break } } if PublishTimeOut MsgBox Activity took more than 20 seconds BlockInput off}Captivate_RecordAdditionalSlides(){ Send !ie WinWait Record Send !i Send {NumPadEnter} WinWait ahk_class TCWToolDockForm.UnicodeClass, ,5 WinGetPos wx, wy, , ,ahk_class TCWToolDockForm.UnicodeClass RememberMousePos("Screen") CoordMode Mouse, Screen MouseClick left, % wx + 5, % wy + 5, ,0 RestoreMousePos() Send r};============= F12 == Publish to HTML ==========================$F12::if LectoraActive(){ Lectora_PublishToHtml(true) return}if CaptivateActive(){ Captivate_RecordAdditionalSlid es() return}; No application wants this hotkey;Send {F12}return ;
;========== Shift - F12 == Publish to HTML (changes only) ==============$+F12::if LectoraActive(){ Lectora_PublishToHtml(false) return}; No application wants this hotkey;Send {+F12}return ;
return ; shouldn't reach labels below in normal loading;============= Auto-save ================; This subroutine is called by a timer. When the current window is Lectora,; the current file is saved.;LectoraAutoSave:if LectoraActive(){ ; if the user is active, try again in 1 minute, otherwise save if (A_TimeIdle < 10000) { ; Need at least 10 seconds idle before autosaving (otherwise ; this workaround causes the user to loose the current focus, ; for example the text block being edited, and this is annoying) SetTimer LectoraAutoSave, 60000 } else { ; User is not active Send !fsundefined Save the current title SetTimer LectoraAutoSave, 600000 ; reset timer }}return ;
Discussions have been disabled for this post