diff --git a/LUAMACROS/2nd_keyboard_if_using_luamacros.ahk b/LUAMACROS/2nd_keyboard_if_using_luamacros.ahk index a3f6c5a..5be0224 100644 --- a/LUAMACROS/2nd_keyboard_if_using_luamacros.ahk +++ b/LUAMACROS/2nd_keyboard_if_using_luamacros.ahk @@ -26,7 +26,6 @@ Menu, Tray, Icon, shell32.dll, 283 ; this changes the tray icon to a little keyb ; Lots of other explanatory videos other AHK scripts can be found on my youtube channel! https://www.youtube.com/user/TaranVH/videos ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ;-------------2ND KEYBOARD USING LUAMACROS----------------- #IfWinActive ahk_exe Adobe Premiere Pro.exe ;---EVERYTHING BELOW THIS LINE WILL ONLY WORK INSIDE PREMIERE PRO. But you can change this to anything you like. You can use Window Spy to determine the ahk_exe of any program, so that your macros will only work when and where you want them to. @@ -35,8 +34,13 @@ Menu, Tray, Icon, shell32.dll, 283 ; this changes the tray icon to a little keyb #IfWinActive ;---- This will allow for everything below this line to work in ANY application. -~F24:: -FileRead, key, C:\AHK\2nd-keyboard\support_files\keypressed.txt +; ~F24:: this can be disabled since we now activate this script via the command line, every time a key is pressed +; FileRead, key, C:\AHK\2nd-keyboard\support_files\keypressed.txt for the same reason we no longer need this +key = null ; initialize the key variable +for n, param in A_Args ; For each parameter passed over command line, the lua script does this (autohotkey.exe script.ahk key) +{ + key = %param% +} tippy(key) ;<--- this function will just launch a quick tooltip that shows you what key you pressed. OPTIONAL. If (key = "o") preset("flip horizontal") @@ -189,6 +193,7 @@ Send {NumpadDiv} else if(key = "numMult") Send {NumpadMult} +ExitApp ; make sure the script closes when it's done so it doesn't fill up the tray. Return ;from luamacros F24 ;THE BLOCK OF CODE ABOVE is the original, simple Luamacros-dependant script. @@ -242,4 +247,4 @@ msgbox, you launched COPY with the parameter %bar% paste(foo){ msgbox, you launched PASTE with the parameter %foo% -} \ No newline at end of file +} diff --git a/LUAMACROS/README.md b/LUAMACROS/README.md index f8c98cf..69c93a6 100644 --- a/LUAMACROS/README.md +++ b/LUAMACROS/README.md @@ -13,7 +13,7 @@ A quickstart guide for using a second keyboard purely for macros on Windows. 1. Ensure that both your keyboards are plugged in. 2. Download and install [LuaMacros](http://www.hidmacros.eu/forum/viewtopic.php?f=10&t=241#p794) and [AuthoHotkey](https://autohotkey.com/). 3. Download `2nd_keyboard_if_using_luamacros.ahk`, `SECOND_KEYBOARD_script_for_LUA_MACROS.lua`, and `keypressed.txt` from this github repository, by clicking on the RAW button for each, and then selecting FILE > SAVE AS. Save them all into the same folder. I STRONGLY recommend that you use `C:\AHK\2nd-keyboard\LUAMACROS`. That way, you won't have to change any file paths at all! The only downside is that ALL users will have access to those scripts. -4. Open `SECOND_KEYBOARD_script_for_LUA_MACROS.lua` using LuaMacros.exe, which will allow you to view and modify the code. You'll need to change the file path of keypressed.txt at least. +4. Open `SECOND_KEYBOARD_script_for_LUA_MACROS.lua` using LuaMacros.exe, which will allow you to view and modify the code. You'll need to change the file path of keypressed.txt at least. On line 43, you'll need to change the path to wherever you're saving the autohotkey script to. You might also need to add autohotkey.exe to your PATH environment variable. 5. Click on the "play" arrow button. An identification window should pop up. Press any key on your 2nd keyboard, and luamacros will identify that device as your 2nd keyboard. 6. Typing on your 2nd keyboard should no longer work, since LuaMacros is now intercepting and blocking those keystrokes. 7. Press the spacebar on your second keyboard, then check keypressed.txt to see if it now contains the string "spacebar". If so, you got it working! @@ -21,6 +21,7 @@ A quickstart guide for using a second keyboard purely for macros on Windows. 9. Scroll down and find and change the filepath `C:\AHK\2nd-keyboard\LUAMACROS\keypressed.txt` to the correct location of keypressed.txt on your own computer. (If it is different.) 10. `2nd_keyboard_if_using_luamacros.ahk` only has bare functions for proof of concept. You can write your own functions, or copy/paste some from from `Almost_All_Premiere_Functions.ahk`, but you'll probably need to modify them to fit your own system, by changing coordinates, windowClasses, colors, shortcuts, and so on. +11. There is a startup script (runonstartup.bat) that you could use, requiring luamacros.exe in your PATH as well. ### Don't Panic! diff --git a/LUAMACROS/SECOND_KEYBOARD_script_for_LUA_MACROS.lua b/LUAMACROS/SECOND_KEYBOARD_script_for_LUA_MACROS.lua index a8af2e6..cb7861c 100644 --- a/LUAMACROS/SECOND_KEYBOARD_script_for_LUA_MACROS.lua +++ b/LUAMACROS/SECOND_KEYBOARD_script_for_LUA_MACROS.lua @@ -34,13 +34,14 @@ lmc.minimizeToTray = true --Start Script sendToAHK = function (key) --print('It was assigned string: ' .. key) - local file = io.open("C:\\AHK\\2nd-keyboard\\LUAMACROS\\keypressed.txt", "w") -- writing this string to a text file on disk is probably NOT the best method. Feel free to program something better! +-- local file = io.open("C:\\AHK\\2nd-keyboard\\LUAMACROS\\keypressed.txt", "w") -- writing this string to a text file on disk is probably NOT the best method. Feel free to program something better! --If you didn't put your AutoHotKey scripts into C:/AHK, Make sure to substitute the path that leads to your own "keypressed.txt" file, using the double backslashes. --print("we are inside the text file") - file:write(key) - file:flush() --"flush" means "save." Lol. - file:close() - lmc_send_keys('{F24}') -- This presses F24. Using the F24 key to trigger AutoHotKey is probably NOT the best method. Feel free to program something better! +-- file:write(key) +-- file:flush() --"flush" means "save." Lol. +-- file:close() + lmc_spawn('AutoHotkey.exe','C:\\PATH\\TO\\AHK\\SCRIPT.ahk', key) --change C:\\PATH\\TO\\AHK\\SCRIPT.ahk to wherever your ahk script is, you might need to add AutoHotkey.exe to your path +-- lmc_send_keys('{F24}') -- Disable this, as we can trigger the ahk script using lmc_spawn, above end local config = { diff --git a/LUAMACROS/runonstartup.bat b/LUAMACROS/runonstartup.bat new file mode 100644 index 0000000..d3145c0 --- /dev/null +++ b/LUAMACROS/runonstartup.bat @@ -0,0 +1,6 @@ +@REM this is a simple script you can use if you want your second keyboard to initialize on startup. you'll need autohotkey.exe and luamacros.exe in your PATH environment variable. +@REM also make sure to switch out the paths to where your lua script and ahk scripts are, respectively. +@REM move this to your startup folder (Windows + R, shell:startup) + +start /MIN LuaMacros.exe -r D:/Scripts/macrokb1.lua +start /MIN autohotkey.exe D:/Scripts/macrokb1.ahk