2nd-keyboard icon indicating copy to clipboard operation
2nd-keyboard copied to clipboard

We need something better for creating the file

Open zurbo opened this issue 8 years ago • 17 comments

io.open("C:\\Users\\TaranVanHemert\\Documents\\keypressed.txt", "w")

For someone who don't know lua (or don't know programming at all) he has to change the code himself... I Will search for something better

zurbo avatar Apr 08 '16 07:04 zurbo

Why not just create the file in the directory the script has been initialised from?

tom-sherman avatar Apr 08 '16 08:04 tom-sherman

That seems to be a good idea but some directory need admins right to be written on windows :'( A way to choose where the user want to create the file sounds a lot better to me

zurbo avatar Apr 08 '16 08:04 zurbo

The script is more than likely going to be ran from a directory that the user has access to, as that user has either downloaded it from the internet or created it themselves.

tom-sherman avatar Apr 08 '16 08:04 tom-sherman

local home = os.getenv("HOMEDRIVE") .. os.getenv("HOMEPATH"); print (' '); print ('Your home folder is: ' .. home); [...] local file = io.open(home .. "\\Documents\\keypressed.txt", "w");

I have done that... no pull request for the moment cause i don't know how to program the file path in ahk :')

zurbo avatar Apr 08 '16 11:04 zurbo

I TOTES AGREE! Writing to a text file on disk is dumb, but I don't know how to write to RAM. Is that what this will do?

TaranVH avatar Apr 08 '16 20:04 TaranVH

hmmm ram is not a good idea since in an OS a program can't access to the ram of another program :( BUUT there is a solution :') (I think i'm not a good user of AHK I have never used it before today) https://www.autohotkey.com/docs/Scripts.htm#cmd with os.execute() you can execute batch command in lua script so ... also today I worked on your lua script and I find how to use modifiers keys how to catch pause and printscreen key how to fix the numlock/capslock/scrlock usage and also stated to make it compatible with multiple macro keyboards and others layouts than ANSI-US

zurbo avatar Apr 08 '16 20:04 zurbo

You could wrap the whole thing in another script, then both processes will be accessible within the same environment.

tom-sherman avatar Apr 08 '16 21:04 tom-sherman

what is the point ? Why having the same env could help ? passing keypress in an env variable is not really a good idea too if it's what you want to do

zurbo avatar Apr 09 '16 09:04 zurbo

What's the point? So you don't have to write to disk. The host script sits in between lua-macros and autohotkey and does all the work without writing to disk.

tom-sherman avatar Apr 10 '16 20:04 tom-sherman

Does AHK can read env variables ? I think it's better to use command line argument but it could be a good idea too

zurbo avatar Apr 10 '16 20:04 zurbo

Can PostMessage be used instead of a file altogether?

As described on this page

The workflow: hidmacros.exe catches the keypress, runs sendmessage.ahk which in return sends the message to shortcuts_pad.ahk. shortcuts_pad.ahk then searches the settings.xml for the right shortcut and uses execute.ahk to execute the command.

Setup: connect your second (usb) keyboardrun hidmacros.exe Posted Image click „new“ enter a name for this shortcut (i just use the name of the key of the second keyboard)click „scan“ then press the desired key on your second keyboardactivate the last button at the bottom „run application“insert „sendmessage.ahk“ + the name of your shortcut key (just use the same name as above)

Amoenus avatar Apr 11 '16 09:04 Amoenus

ok, my first pull request was really bad... But we can pass the key press via command line arguments to the script i've done that for a litlle keyboard and this work pretty well:

the ahk script:

Loop %0%
{
    param := %A_Index%
    If param = 1
    {
        Send, https://i.imgur.com/lzfy9Sq.png{enter}
        Return
    }
    If param = 2
    {
        Send, https://i.imgur.com/jAe0Lnb.gif{enter}
        Return
    }
    If param = 6
    {
        Send, https://i.imgur.com/X3T6lMl.png{enter}
        Return
    }
    If param = 7
    {
        Send, https://i.imgur.com/FuysN1K.jpg{enter}
        Return
    }
    Else
    {
        MsgBox, %param% Not associated.
        Return
    }
}

and the (simple) lua script:

lmc_device_set_name('macrosPad', 'kb_device_ID');
lmc.minimizeToTray = true;
lmc_minimize();

key = {
    [8] = "6",
    [13] = "14",
    [48] = "10",
    [49] = "7",
    [50] = "11",
    [51] = "15",
    [52] = "8",
    [53] = "12",
    [54] = "16",
    [55] = "9",
    [56] = "13",
    [57] = "17"
};

lmc_set_handler('macrosPad', function(button, direction)
    if (direction == 0) then
       os.execute("start path_to_ahk_executable path_to_your_ahk_script" .. " " .. key[button]);
    end
end)

why my first pull request was bad ? because without start in the os.execute function the script will run AHK and wait until it end (so all the keypresses made by AHK will be made in the command line opened by luamacro)

zurbo avatar May 17 '16 17:05 zurbo

What about reading and writing to IOstream and add a 3rd script to call the existing scripts and forward those?

Sasszem avatar Feb 05 '17 13:02 Sasszem

@Sasszem this is basically the gist of what I was trying to say. I don't know anything about lua or it's IOstreams but in Node.js I would use a stream to accomplish this,

tom-sherman avatar Feb 05 '17 13:02 tom-sherman

@tom-sherman http://www.lua.org/pil/21.1.html

Sasszem avatar Feb 06 '17 18:02 Sasszem

@tom-sherman http://www.lua.org/pil/21.1.html

Sasszem avatar Feb 06 '17 20:02 Sasszem

I TOTES AGREE! Writing to a text file on disk is dumb, but I don't know how to write to RAM. Is that what this will do?

How about a ram disk? I use this tool https://sourceforge.net/projects/imdisk-toolkit/ But you can use any RamDisk utility and write the keypressed.txt to there!

SanderCokart avatar Apr 26 '20 15:04 SanderCokart