var VK_SHIFT = 0x10; var VK_CONTROL = 0x11; var VK_MENU = 0x12; function doBeforeMouseEvent(macro) { var vCommand = ""; if (macro.alt) vCommand += "Shell.KeyboardEvent(" + VK_MENU + ", 0, 0, 0);\r\n"; if (macro.ctrl) vCommand += "Shell.KeyboardEvent(" + VK_CONTROL + ", 0, 0, 0);\r\n"; if (macro.shift) vCommand += "Shell.KeyboardEvent(" + VK_SHIFT + ", 0, 0, 0);\r\n"; return vCommand; } function doAfterMouseEvent(macro) { var vCommand = ""; if (macro.shift) vCommand += "\r\nShell.KeyboardEvent(" + VK_SHIFT + ", 0, " + eKeyboardEventFlagKeyUp + ", 0);"; if (macro.ctrl) vCommand += "\r\nShell.KeyboardEvent(" + VK_CONTROL + ", 0, " + eKeyboardEventFlagKeyUp + ", 0);"; if (macro.alt) vCommand += "\r\nShell.KeyboardEvent(" + VK_MENU + ", 0, " + eKeyboardEventFlagKeyUp + ", 0);"; if ( macro.sleep > 0 ) vCommand += "\r\nSleep("+ macro.sleep + ");"; return vCommand; } function collectSearchFlags(macro) { var dwFlags = 0; if ( macro.match_case ) dwFlags += FIND_MATCH_CASE; if ( macro.whole_word ) dwFlags += FIND_WHOLE_WORD; if ( macro.regexp ) dwFlags += FIND_REGEXP; if ( macro.up ) dwFlags += FIND_DIRECTION_UP; if ( macro.check_hidden ) dwFlags += FIND_HIDDEN_TEXT; if ( macro.wrap ) dwFlags += FIND_WRAP; if ( macro.hex ) dwFlags += FIND_HEX; if ( macro.extend_sel ) dwFlags += FIND_EXTENDED_SEL; if ( macro.close_on_end ) dwFlags += FIND_CLOSE_ON_FOUND; if ( macro.mark ) dwFlags += FIND_HIGHLIGHT; if ( macro.bookmark ) dwFlags += FIND_BOOKMARK; return dwFlags; } function onMacroStepTranslate() { var vCommand; switch (this.name) { case "MouseMove": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventMove, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "LeftMouseDown": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventLeftDown, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "LeftMouseUp": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventLeftUp, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "LeftMouseClick": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventLeftDown, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand = "Shell.MouseEvent(eMouseEventLeftUp, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "RightMouseDown": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventRightDown, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "RightMouseUp": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventRightUp, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "MiddleMouseDown": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventMiddleDown, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "MiddleMouseUp": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventMiddleUp, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "LeftMouseDblClk": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventMiddleDown, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand = "Shell.MouseEvent(eMouseEventMiddleUp, 0, CreatePoint(" + this.x + "," + this.y + "));"; vCommand += doAfterMouseEvent(this); break; case "MouseWheel": vCommand += doBeforeMouseEvent(this); vCommand = "Shell.MouseEvent(eMouseEventWhell, " + this.delta + ", null);"; vCommand += doAfterMouseEvent(this); break; case "MouseWheelEx": vCommand = "Shell.MouseEvent(eMouseEventWhell, " + this.delta + ", null);"; break; case "Message": vCommand = "Shell.SendMessage(0, " + this.msg + ", " + this.high + ", " + this.low + ");"; break; case "Command": vCommand = "ExecuteCommand(\"" + this.cmd + "\", " + this.count + ");"; break; case "Sleep": vCommand = "Sleep(" + this.msec + ");"; break; case "GoTo": vCommand = "if ( ActiveView != null ) ActiveView.GoTo(\"" + this.pos + "\", " + this.anchor + ");"; break; case "Text": vCommand = "if ( ActiveDocument != null ) ActiveView.Position = ActiveDocument.InsertText(ActiveView.Position, \"" + this.text + "\", HE_ACTION_TYPING);"; break; case "NewLine": var sNewLines = ""; for (i = 0; i < this.count; i++) sNewLines += "\\r\\n"; vCommand = "if ( ActiveDocument != null ) ActiveView.Position = ActiveDocument.InsertText(ActiveView.Position, \"" + sNewLines + "\", HE_ACTION_TYPING);"; break; case "Find": var dwFlags = collectSearchFlags(this); vCommand = "FindEx(\"" + this.what + "\", " + this.type + ", " + this.action + ", " + this.search_in + ", " + this.result + ", " + dwFlags + ");"; break; case "Replace": var dwFlags = collectSearchFlags(this); vCommand = "ReplaceEx(\"" + this.what + "\", \"" + this.to + "\", " + this.type + ", " + this.action + ", " + this.search_in + ", " + this.result + ", " + dwFlags + ");"; break; default: vCommand = this.name; break; } return vCommand; } // add optional script information, nice when you want to see something meaningful // in plugin description in options dialog Application.AddScriptInfo("Macro Conversion Plugin", "1.0.0.0", "The script does translation of recorded macro steps into HippoEDIT JavaScript", "HippoEDIT", "supportbox@hippoedit.com", "http://www.hippoedit.com"); Application.RegisterMacroTranslator("Macros.JSConvert", "Convert to JavaScript...", "Convert active macro to JavaScript file", -1, onMacroStepTranslate);