' (c) opk44 2011
' version 0.1.4 - 2011-11-11
' http://akelpad.sourceforge.net/forum/viewtopic.php?p=15365#15365
'
' Использовано "Appendix A - Virtual Key codes" AkelPad Plugins Manual (Surveyor)
'
' Usage:
' Call("Scripts::Main", 1, "Macro2SendKeys.vbs")

' Known BUGS & LIMITATIONS:
' 1) Не умеет отслеживать переключения раскладки RUS/LAT (комбинация только модификаторов
'   {Ctrl}+{Shift} или {Alt}+{Shift})
' 2) Диалог выбора файлов работает только в Win2000/WinXP (на Vista/Win7 не проверялось,
'    но, по-видимому, работать не будет)
' 3) Инициализация директории в диалоге выбора файла-макроса иногда не срабатывает
'    (вместо указанной  стартовой папки макросов можем оказаться в папке, указанной
'    в LastDirectory (см. "AkelPad.ini")

Option Explicit

' режимы открытия файла (используется только "для чтения")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' индексы колонок хранения текущего состояния клавиш (массив "myarr")
Const alt_key_status = 0, ctrl_key_status = 1, shift_key_status = 2, other_key_status = 3

Dim myarr(999, 3)  ' массив для SendKeys-последовательностей (<= 1000, если нужно - увеличьте!).
Dim allkeys  ' для предварительной грубой оценки размера макроса
Dim first_index, CountKeyDown
Dim dic_f, dic_k  ' Словари флагов и ключей
Dim WM_COMMAND, IDM_FILE_NEW, hMainWnd
Dim i, j, k  ' Счетчики
Dim fn_macro, fsi, fi_size, fi, VbCrLf
Dim objDialog, intResult, pAkelDir
Dim keyword, flag_key, myitem
Dim shbl_head_vbs, shbl_head_js, shbl_sk
Dim strMsg

'--------- Словари флагов и ключей ----------
' Словарь флагов (состояний нажато/отпущено)
Set dic_f = CreateObject("Scripting.Dictionary")
dic_f.add &H00, "{0x00}-{normal key was press    (down)}"
dic_f.add &H01, "{0x01}-{extended key was press  (down)}"
dic_f.add &H02, "{0x02}-{normal key was released   (up)}"
dic_f.add &H03, "{0x03}-{extended key was released (up)}"

' Словарь ключей
Set dic_k = CreateObject("Scripting.Dictionary")
dic_k.add &H00, "x00" '"{0x00}-{Undefined}"
dic_k.add &H01, "x01" '"{0x01}-{Left mouse button}"
dic_k.add &H02, "x02" '"{0x02}-{Right mouse button}"
dic_k.add &H03, "x03" '"{0x03}-{Control-break processing}"
dic_k.add &H04, "x04" '"{0x04}-{Middle mouse button (three-button mouse)}"
dic_k.add &H05, "x05" '"{0x05}-{X1 mouse button}"
dic_k.add &H06, "x06" '"{0x06}-{X2 mouse button}"
dic_k.add &H07, "x07" '"{0x07}-{Undefined}"
dic_k.add &H08, "{BACKSPACE}" '"{0x08}-{BACKSPACE key}"
dic_k.add &H09, "{TAB}" '"{0x09}-{TAB key}"
dic_k.add &H0A, "x0A" '"{0x0A}-{Reserved}"
dic_k.add &H0B, "x0B" '"{0x0B}-{Reserved}"
dic_k.add &H0C, "CLEAR" '"{0x0C}-{CLEAR key}"
dic_k.add &H0D, "{ENTER}" '"{0x0D}-{ENTER key}"
dic_k.add &H0E, "x0E" '"{0x0E}-{Undefined}"
dic_k.add &H0F, "x0F" '"{0x0F}-{Undefined}"
dic_k.add &H10, "+" '"{0x10}-{SHIFT key}"
dic_k.add &H11, "^" '"{0x11}-{CTRL key}"
dic_k.add &H12, "%" '"{0x12}-{ALT key}"
dic_k.add &H13, "PAUSE" '"{0x13}-{PAUSE key}"
dic_k.add &H14, "{CAPSLOCK}" '"{0x14}-{CAPS LOCK key}"
dic_k.add &H15, "x15" '"{0x15}-{IME Kana mode | IME Hanguel mode (maintained for compatibility; use VK_HANGUL) | IME Hangul mode}"
dic_k.add &H16, "x16" '"{0x16}-{Undefined}"
dic_k.add &H17, "x17" '"{0x17}-{IME Junja mode}"
dic_k.add &H18, "x18" '"{0x18}-{IME final mode}"
dic_k.add &H19, "x19" '"{0x19}-{IME Hanja mode | IME Kanji mode}"
dic_k.add &H1A, "x1A" '"{0x1A}-{Undefined}"
dic_k.add &H1B, "{ESC}" '"{0x1B}-{ESC key}"
dic_k.add &H1C, "x1C" '"{0x1C}-{IME convert}"
dic_k.add &H1D, "x1D" '"{0x1D}-{IME nonconvert}"
dic_k.add &H1E, "x1E" '"{0x1E}-{IME accept}"
dic_k.add &H1F, "x1F" '"{0x1F}-{IME mode change request}"
dic_k.add &H20, " " '"{0x20}-{SPACEBAR}"
dic_k.add &H21, "{PGUP}" '"{0x21}-{PAGE UP key}"
dic_k.add &H22, "{PGDN}" '"{0x22}-{PAGE DOWN key}"
dic_k.add &H23, "{END}" '"{0x23}-{END key}"
dic_k.add &H24, "{HOME}" '"{0x24}-{HOME key}"
dic_k.add &H25, "{LEFT}" '"{0x25}-{LEFT ARROW key}"
dic_k.add &H26, "{UP}" '"{0x26}-{UP ARROW key}"
dic_k.add &H27, "{RIGHT}" '"{0x27}-{RIGHT ARROW key}"
dic_k.add &H28, "{DOWN}" '"{0x28}-{DOWN ARROW key}"
dic_k.add &H29, "SELECT" '"{0x29}-{SELECT key}"
dic_k.add &H2A, "PRINT" '"{0x2A}-{PRINT key}"
dic_k.add &H2B, "EXECUTE" '"{0x2B}-{EXECUTE key}"
dic_k.add &H2C, "{PRTSC}" '"{0x2C}-{PRINT SCREEN key}"
dic_k.add &H2D, "{INS}" '"{0x2D}-{INS key}"
dic_k.add &H2E, "{DEL}" '"{0x2E}-{DEL key}"
dic_k.add &H2F, "{HELP}" '"{0x2F}-{HELP key}"
dic_k.add &H30, "0" '"{0x30}-{0 key}"
dic_k.add &H31, "1" '"{0x31}-{1 key}"
dic_k.add &H32, "2" '"{0x32}-{2 key}"
dic_k.add &H33, "3" '"{0x33}-{3 key}"
dic_k.add &H34, "4" '"{0x34}-{4 key}"
dic_k.add &H35, "5" '"{0x35}-{5 key}"
dic_k.add &H36, "6" '"{0x36}-{6 key}"
dic_k.add &H37, "7" '"{0x37}-{7 key}"
dic_k.add &H38, "8" '"{0x38}-{8 key}"
dic_k.add &H39, "9" '"{0x39}-{9 key}"
dic_k.add &H3A, "x3A" '"{0x3A}-{Undefined}"
dic_k.add &H3B, "x3B" '"{0x3B}-{Undefined}"
dic_k.add &H3C, "x3C" '"{0x3C}-{Undefined}"
dic_k.add &H3D, "x3D" '"{0x3D}-{Undefined}"
dic_k.add &H3E, "x3E" '"{0x3E}-{Undefined}"
dic_k.add &H3F, "x3F" '"{0x3F}-{Undefined}"
dic_k.add &H40, "x40" '"{0x40}-{Undefined}"
dic_k.add &H41, "a" '"{0x41}-{A key}"
dic_k.add &H42, "b" '"{0x42}-{B key}"
dic_k.add &H43, "c" '"{0x43}-{C key}"
dic_k.add &H44, "d" '"{0x44}-{D key}"
dic_k.add &H45, "e" '"{0x45}-{E key}"
dic_k.add &H46, "f" '"{0x46}-{F key}"
dic_k.add &H47, "g" '"{0x47}-{G key}"
dic_k.add &H48, "h" '"{0x48}-{H key}"
dic_k.add &H49, "i" '"{0x49}-{I key}"
dic_k.add &H4A, "j" '"{0x4A}-{J key}"
dic_k.add &H4B, "k" '"{0x4B}-{K key}"
dic_k.add &H4C, "l" '"{0x4C}-{L key}"
dic_k.add &H4D, "m" '"{0x4D}-{M key}"
dic_k.add &H4E, "n" '"{0x4E}-{N key}"
dic_k.add &H4F, "o" '"{0x4F}-{O key}"
dic_k.add &H50, "p" '"{0x50}-{P key}"
dic_k.add &H51, "q" '"{0x51}-{Q key}"
dic_k.add &H52, "r" '"{0x52}-{R key}"
dic_k.add &H53, "s" '"{0x53}-{S key}"
dic_k.add &H54, "t" '"{0x54}-{T key}"
dic_k.add &H55, "u" '"{0x55}-{U key}"
dic_k.add &H56, "v" '"{0x56}-{V key}"
dic_k.add &H57, "w" '"{0x57}-{W key}"
dic_k.add &H58, "x" '"{0x58}-{X key}"
dic_k.add &H59, "y" '"{0x59}-{Y key}"
dic_k.add &H5A, "z" '"{0x5A}-{Z key}"
dic_k.add &H5B, "x5B" '"{0x5B}-{Left Windows key (Microsoft® Natural® keyboard)}"
dic_k.add &H5C, "x5C" '"{0x5C}-{Right Windows key (Natural keyboard)}"
dic_k.add &H5D, "x5D" '"{0x5D}-{Applications key (Natural keyboard)}"
dic_k.add &H5E, "x5E" '"{0x5E}-{Reserved}"
dic_k.add &H5F, "x5F" '"{0x5F}-{Computer Sleep key}"
dic_k.add &H60, "x60" '"{0x60}-{Numeric keypad 0 key}"
dic_k.add &H61, "x61" '"{0x61}-{Numeric keypad 1 key}"
dic_k.add &H62, "x62" '"{0x62}-{Numeric keypad 2 key}"
dic_k.add &H63, "x63" '"{0x63}-{Numeric keypad 3 key}"
dic_k.add &H64, "x64" '"{0x64}-{Numeric keypad 4 key}"
dic_k.add &H65, "x65" '"{0x65}-{Numeric keypad 5 key}"
dic_k.add &H66, "x66" '"{0x66}-{Numeric keypad 6 key}"
dic_k.add &H67, "x67" '"{0x67}-{Numeric keypad 7 key}"
dic_k.add &H68, "x68" '"{0x68}-{Numeric keypad 8 key}"
dic_k.add &H69, "x69" '"{0x69}-{Numeric keypad 9 key}"
dic_k.add &H6A, "x6A" '"{0x6A}-{Multiply key}"
dic_k.add &H6B, "{+}" '"{0x6B}-{Add key}"
dic_k.add &H6C, "x6C" '"{0x6C}-{Separator key}"
dic_k.add &H6D, "-" '"{0x6D}-{Subtract key}"
dic_k.add &H6E, "x6E" '"{0x6E}-{Decimal key}"
dic_k.add &H6F, "x6F" '"{0x6F}-{Divide key}"
dic_k.add &H70, "{F1}" '"{0x70}-{F1 key}"
dic_k.add &H71, "{F2}" '"{0x71}-{F2 key}"
dic_k.add &H72, "{F3}" '"{0x72}-{F3 key}"
dic_k.add &H73, "{F4}" '"{0x73}-{F4 key}"
dic_k.add &H74, "{F5}" '"{0x74}-{F5 key}"
dic_k.add &H75, "{F6}" '"{0x75}-{F6 key}"
dic_k.add &H76, "{F7}" '"{0x76}-{F7 key}"
dic_k.add &H77, "{F8}" '"{0x77}-{F8 key}"
dic_k.add &H78, "{F9}" '"{0x78}-{F9 key}"
dic_k.add &H79, "{F10}" '"{0x79}-{F10 key}"
dic_k.add &H7A, "{F11}" '"{0x7A}-{F11 key}"
dic_k.add &H7B, "{F12}" '"{0x7B}-{F12 key}"
dic_k.add &H7C, "{F13}" '"{0x7C}-{F13 key}"
dic_k.add &H7D, "{F14}" '"{0x7D}-{F14 key}"
dic_k.add &H7E, "{F15}" '"{0x7E}-{F15 key}"
dic_k.add &H7F, "{F16}" '"{0x7F}-{F16 key}"
dic_k.add &H80, "{F17}" '"{0x80}-{F17 key}"
dic_k.add &H81, "{F18}" '"{0x81}-{F18 key}"
dic_k.add &H82, "{F19}" '"{0x82}-{F19 key}"
dic_k.add &H83, "{F20}" '"{0x83}-{F20 key}"
dic_k.add &H84, "{F21}" '"{0x84}-{F21 key}"
dic_k.add &H85, "{F22}" '"{0x85}-{F22 key}"
dic_k.add &H86, "{F23}" '"{0x86}-{F23 key}"
dic_k.add &H87, "{F24}" '"{0x87}-{F24 key}"
dic_k.add &H88, "x88" '"{0x88}-{Unassigned}"
dic_k.add &H89, "x89" '"{0x89}-{Unassigned}"
dic_k.add &H8A, "x8A" '"{0x8A}-{Unassigned}"
dic_k.add &H8B, "x8B" '"{0x8B}-{Unassigned}"
dic_k.add &H8C, "x8C" '"{0x8C}-{Unassigned}"
dic_k.add &H8D, "x8D" '"{0x8D}-{Unassigned}"
dic_k.add &H8E, "x8E" '"{0x8E}-{Unassigned}"
dic_k.add &H8F, "x8F" '"{0x8F}-{Unassigned}"
dic_k.add &H90, "{NUMLOCK}" '"{0x90}-{NUM LOCK key}"
dic_k.add &H91, "{SCROLLLOCK}" '"{0x91}-{SCROLL LOCK key}"
dic_k.add &H92, "x92" '"{0x92}-{OEM specific}"
dic_k.add &H93, "x93" '"{0x93}-{OEM specific}"
dic_k.add &H94, "x94" '"{0x94}-{OEM specific}"
dic_k.add &H95, "x95" '"{0x95}-{OEM specific}"
dic_k.add &H96, "x96" '"{0x96}-{OEM specific}"
dic_k.add &H97, "x97" '"{0x97}-{Unassigned}"
dic_k.add &H98, "x98" '"{0x98}-{Unassigned}"
dic_k.add &H99, "x99" '"{0x99}-{Unassigned}"
dic_k.add &H9A, "x9A" '"{0x9A}-{Unassigned}"
dic_k.add &H9B, "x9B" '"{0x9B}-{Unassigned}"
dic_k.add &H9C, "x9C" '"{0x9C}-{Unassigned}"
dic_k.add &H9D, "x9D" '"{0x9D}-{Unassigned}"
dic_k.add &H9E, "x9E" '"{0x9E}-{Unassigned}"
dic_k.add &H9F, "x9F" '"{0x9F}-{Unassigned}"
dic_k.add &HA0, "Left_SHIFT" '"{0xA0}-{Left SHIFT key}"
dic_k.add &HA1, "Right_SHIFT" '"{0xA1}-{Right SHIFT key}"
dic_k.add &HA2, "Left_CONTROL" '"{0xA2}-{Left CONTROL key}"
dic_k.add &HA3, "Right_CONTROL" '"{0xA3}-{Right CONTROL key}"
dic_k.add &HA4, "Left_MENU" '"{0xA4}-{Left MENU key}"
dic_k.add &HA5, "Right_MENU" '"{0xA5}-{Right MENU key}"
dic_k.add &HA6, "xA6" '"{0xA6}-{Browser Back key}"
dic_k.add &HA7, "xA7" '"{0xA7}-{Browser Forward key}"
dic_k.add &HA8, "xA8" '"{0xA8}-{Browser Refresh key}"
dic_k.add &HA9, "xA9" '"{0xA9}-{Browser Stop key}"
dic_k.add &HAA, "xAA" '"{0xAA}-{Browser Search key}"
dic_k.add &HAB, "xAB" '"{0xAB}-{Browser Favorites key}"
dic_k.add &HAC, "xAC" '"{0xAC}-{Browser Start and Home key}"
dic_k.add &HAD, "xAD" '"{0xAD}-{Volume Mute key}"
dic_k.add &HAE, "xAE" '"{0xAE}-{Volume Down key}"
dic_k.add &HAF, "xAF" '"{0xAF}-{Volume Up key}"
dic_k.add &HB0, "xB0" '"{0xB0}-{Next Track key}"
dic_k.add &HB1, "xB1" '"{0xB1}-{Previous Track key}"
dic_k.add &HB2, "xB2" '"{0xB2}-{Stop Media key}"
dic_k.add &HB3, "xB3" '"{0xB3}-{Play/Pause Media key}"
dic_k.add &HB4, "xB4" '"{0xB4}-{Start Mail key}"
dic_k.add &HB5, "xB5" '"{0xB5}-{Select Media key}"
dic_k.add &HB6, "xB6" '"{0xB6}-{Start Application 1 key}"
dic_k.add &HB7, "xB7" '"{0xB7}-{Start Application 2 key}"
dic_k.add &HB8, "xB8" '"{0xB8}-{Reserved}"
dic_k.add &HB9, "xB9" '"{0xB9}-{Reserved}"
dic_k.add &HBA, ";" '"{0xBA}-{Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the ';:' key}"
dic_k.add &HBB, "{+}" '"{0xBB}-{For any country/region, the '+' key}"
dic_k.add &HBC, "," '"{0xBC}-{For any country/region, the ',' key}"
dic_k.add &HBD, "-" '"{0xBD}-{For any country/region, the '-' key}"
dic_k.add &HBE, "." '"{0xBE}-{For any country/region, the '.' key}"
dic_k.add &HBF, "/" '"{0xBF}-{Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '/?' key}"
dic_k.add &HC0, "{~}" '"{0xC0}-{Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '`~' key}"
dic_k.add &HC1, "xC1" '"{0xC1}-{Reserved}"
dic_k.add &HC2, "xC2" '"{0xC2}-{Reserved}"
dic_k.add &HC3, "xC3" '"{0xC3}-{Reserved}"
dic_k.add &HC4, "xC4" '"{0xC4}-{Reserved}"
dic_k.add &HC5, "xC5" '"{0xC5}-{Reserved}"
dic_k.add &HC6, "xC6" '"{0xC6}-{Reserved}"
dic_k.add &HC7, "xC7" '"{0xC7}-{Reserved}"
dic_k.add &HC8, "xC8" '"{0xC8}-{Reserved}"
dic_k.add &HC9, "xC9" '"{0xC9}-{Reserved}"
dic_k.add &HCA, "xCA" '"{0xCA}-{Reserved}"
dic_k.add &HCB, "xCB" '"{0xCB}-{Reserved}"
dic_k.add &HCC, "xCC" '"{0xCC}-{Reserved}"
dic_k.add &HCD, "xCD" '"{0xCD}-{Reserved}"
dic_k.add &HCE, "xCE" '"{0xCE}-{Reserved}"
dic_k.add &HCF, "xCF" '"{0xCF}-{Reserved}"
dic_k.add &HD0, "xD0" '"{0xD0}-{Reserved}"
dic_k.add &HD1, "xD1" '"{0xD1}-{Reserved}"
dic_k.add &HD2, "xD2" '"{0xD2}-{Reserved}"
dic_k.add &HD3, "xD3" '"{0xD3}-{Reserved}"
dic_k.add &HD4, "xD4" '"{0xD4}-{Reserved}"
dic_k.add &HD5, "xD5" '"{0xD5}-{Reserved}"
dic_k.add &HD6, "xD6" '"{0xD6}-{Reserved}"
dic_k.add &HD7, "xD7" '"{0xD7}-{Reserved}"
dic_k.add &HD8, "xD8" '"{0xD8}-{Unassigned}"
dic_k.add &HD9, "xD9" '"{0xD9}-{Unassigned}"
dic_k.add &HDA, "xDA" '"{0xDA}-{Unassigned}"
dic_k.add &HDB, "{[}" '"{0xDB}-{Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '[{' key}"
dic_k.add &HDC, "\" '"{0xDC}-{Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '\|' key}"
dic_k.add &HDD, "{]}" '"{0xDD}-{Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the ']}' key}"
dic_k.add &HDE, "'" '"{0xDE}-{Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the 'single-quote/double-quote' key}"
dic_k.add &HDF, "xDF" '"{0xDF}-{Used for miscellaneous characters; it can vary by keyboard.}"
dic_k.add &HE0, "xE0" '"{0xE0}-{Reserved}"
dic_k.add &HE1, "xE1" '"{0xE1}-{OEM specific}"
dic_k.add &HE2, "xE2" '"{0xE2}-{Either the angle bracket key or the backslash key on the RT 102-key keyboard}"
dic_k.add &HE3, "xE3" '"{0xE3}-{OEM specific}"
dic_k.add &HE4, "xE4" '"{0xE4}-{OEM specific}"
dic_k.add &HE5, "xE5" '"{0xE5}-{IME PROCESS key}"
dic_k.add &HE6, "xE6" '"{0xE6}-{OEM specific}"
dic_k.add &HE7, "xE7" '"{0xE7}-{Used to pass Unicode characters as if they were keystrokes.}"
dic_k.add &HE8, "xE8" '"{0xE8}-{Unassigned}"
dic_k.add &HE9, "xE9" '"{0xE9}-{OEM specific}"
dic_k.add &HEA, "xEA" '"{0xEA}-{OEM specific}"
dic_k.add &HEB, "xEB" '"{0xEB}-{OEM specific}"
dic_k.add &HEC, "xEC" '"{0xEC}-{OEM specific}"
dic_k.add &HED, "xED" '"{0xED}-{OEM specific}"
dic_k.add &HEE, "xEE" '"{0xEE}-{OEM specific}"
dic_k.add &HEF, "xEF" '"{0xEF}-{OEM specific}"
dic_k.add &HF0, "xF0" '"{0xF0}-{OEM specific}"
dic_k.add &HF1, "xF1" '"{0xF1}-{OEM specific}"
dic_k.add &HF2, "xF2" '"{0xF2}-{OEM specific}"
dic_k.add &HF3, "xF3" '"{0xF3}-{OEM specific}"
dic_k.add &HF4, "xF4" '"{0xF4}-{OEM specific}"
dic_k.add &HF5, "xF5" '"{0xF5}-{OEM specific}"
dic_k.add &HF6, "xF6" '"{0xF6}-{Attn key}"
dic_k.add &HF7, "xF7" '"{0xF7}-{CrSel key}"
dic_k.add &HF8, "xF8" '"{0xF8}-{ExSel key}"
dic_k.add &HF9, "xF9" '"{0xF9}-{Erase EOF key}"
dic_k.add &HFA, "xFA" '"{0xFA}-{Play key}"
dic_k.add &HFB, "xFB" '"{0xFB}-{Zoom key}"
dic_k.add &HFC, "xFC" '"{0xFC}-{Reserved for future use}"
dic_k.add &HFD, "xFD" '"{0xFD}-{PA1 key}"
dic_k.add &HFE, "xFE" '"{0xFE}-{Clear key}"
'--------------------------------------

' Формируем путь к папке с макросами
  pAkelDir = AkelPad.GetAkelDir(4)
  pAkelDir = """" & pAkelDir & "\Macros\" & """"

' Диалог выбора файла-макроса для декодирования (не работает на Vista/Win7)
 Set objDialog = CreateObject("UserAccounts.CommonDialog")
 objDialog.InitialDir = pAkelDir
 objDialog.Filter = "Файлы macro (*.macro)|*.macro|Все файлы (*.*)|*.*"
 objDialog.FilterIndex = 1
 intResult = objDialog.ShowOpen
 If intResult = 0 Then
  Wscript.Quit      ' если файл-макрос не выбран, то выходим
 Else               ' основная обработка
  WM_COMMAND=273
  IDM_FILE_NEW=4101      ' команда на создание нового файла
  hMainWnd=AkelPad.GetMainWnd()
  AkelPad.SendMessage hMainWnd, WM_COMMAND, IDM_FILE_NEW, 0
  VbCrLf = Chr(13) & Chr(10)
  shbl_sk = "  WshShell.SendKeys "
  fn_macro = objDialog.FileName
  Set fsi = CreateObject("Scripting.FileSystemObject")
  fi_size = fsi.GetFile(fn_macro).Size    ' получить размер файла-макроса
  AkelPad.ReplaceSel(fn_macro & VbCrLf & "Size: " & fi_size & " bytes (" & _
                     fi_size/8 & " keys)" & VbCrLf & String(40, "-") & VbCrLf)

  allkeys = fi_size\8
  If allkeys > 1000 Then
    MsgBox "Too many keys! Only first 1000 will be converted. "
  End If

  first_index = 0
  CountKeyDown = 0
  Set fi = fsi.OpenTextFile(fn_macro, ForReading, True)
'
  myarr(first_index, alt_key_status) = ""
  myarr(first_index, ctrl_key_status) = ""
  myarr(first_index, shift_key_status) = ""
  myarr(first_index, other_key_status) = ""

  For i = 1 To fi_size Step 8     ' перебираем 8-байтные цепочки "KL-00-00-00-FL-00-00-00"
    keyword = Asc(fi.Read(1))
    fi.Skip(3)
    flag_key = Asc(fi.Read(1))
    myitem = dic_k.Item(keyword)
    fi.Skip(3)
    If flag_key <= &H01 Then  ' клавиша нажата...
        CountKeyDown = CountKeyDown + 1
        Select Case keyword
          Case &H10     ' Shift "on"
            myarr(first_index, shift_key_status) = "+"
          Case &H11     ' Ctrl "on"
            myarr(first_index, ctrl_key_status) = "^"
          Case &H12      ' Alt "on"
            myarr(first_index, alt_key_status) = "%"
          Case Else
            myarr(first_index, other_key_status) = myitem
            first_index = first_index + 1
        End Select
    ElseIf flag_key > &H01 Then  ' клавиша отпущена...
        CountKeyDown = CountKeyDown - 1
        Select Case keyword
          Case &H10
            myarr(first_index, shift_key_status) = ""
          Case &H11
            myarr(first_index, ctrl_key_status) = ""
          Case &H12
            myarr(first_index, alt_key_status) = ""
          Case Else
            If CountKeyDown > 0 Then            ' копирование статуса модификаторов
              myarr(first_index, shift_key_status) = myarr(first_index-1, shift_key_status)
              myarr(first_index, ctrl_key_status) = myarr(first_index-1, ctrl_key_status)
              myarr(first_index, alt_key_status) = myarr(first_index-1, alt_key_status)
              myarr(first_index, other_key_status) = myitem
            End If
        End Select
      End If
  Next
  fi.Close()
 End If

' ---------- вывод содержимого массива (шаблон VBScript)
  shbl_head_vbs = "VBScript template" & VbCrLf & String(40, "-") & VbCrLf & "Dim WshShell" & _
                   VbCrLf & "  Set WshShell = CreateObject(""WScript.Shell"")" & VbCrLf
  AkelPad.ReplaceSel shbl_head_vbs
For j = 0 To first_index ' UBound(myarr, 1)
  strMsg = ""
  For k = 0 To 3
    strMsg = strMsg & myarr(j, k)
  Next
    If Len(strMsg) > 0 Then
      AkelPad.ReplaceSel shbl_sk & """" & strMsg & """" & VbCrLf
    End If
Next
  AkelPad.ReplaceSel(String(40, "-") & VbCrLf)
' ---------- вывод содержимого массива (шаблон JScript)
  shbl_head_js = "JScript template" & VbCrLf & String(40, "-") & VbCrLf & _
                 "  var WshShell = new ActiveXObject(""WScript.Shell"");" & VbCrLf
  AkelPad.ReplaceSel shbl_head_js
For j = 0 To first_index ' UBound(myarr, 1)
  strMsg = ""
  For k = 0 To 3
    strMsg = strMsg & myarr(j, k)
      If (k = 3 And myarr(j, k) = "\") Then   ' удвоение слешей для JScript ("\" -> "\\")
        strMsg = strMsg & "\"
      End If
  Next
    If Len(strMsg) > 0 Then
      AkelPad.ReplaceSel shbl_sk & "(""" & strMsg & """);" & VbCrLf
    End If
Next
  AkelPad.ReplaceSel(String(40, "-") & VbCrLf)
