d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Lua Macro For Logitech Ghub? > Logitech Ghub Macro In Lua
Add Reply New Topic New Poll
Member
Posts: 1,291
Joined: Jul 25 2010
Gold: 500.00
Feb 11 2020 07:05pm
ok so I am trying to create a macro that will hit a number of keys after I just hit one. (cool great, i know they have a built in feature to do that already), but i want to go one step further and have them hit within a 'random' timeframe like 80-120ms. which means i have to code it. luckily there is an easy way to ad scripts in Ghub but As someone who has hardly dabbled in any code I spent an hour or two googling, and then reading the instructions provided from the LUA before i came up with this masterpiece.... it doesn't work. I had fun getting to this point but i'm now stuck any solutions or advice on where I went wrong would be appreciated.

function OnEvent(event, arg)

function Random(a, b )
if not _SEED then
_SEED = GetRunningTime()
math.randomseed(_SEED)
end
return math.random(a, b )

if (event =="2_PRESSED") then


PressKey("w")
Sleep(Random(88, 130))
ReleaseKey("w")
Sleep(Random(75, 120))
PressKey("1")
Sleep(Random(100, 123))
ReleaseKey("1")
Sleep(Random(55, 111))
PressKey("2")
Sleep(Random(80, 120))
ReleaseKey("2")
Sleep(Random(56, 118))
PressKey("3")
Sleep(Random(74, 122))
ReleaseKey("3")

end

end

edit: I can't seem to format this properly but I think it is all correctly formatted in the application.

edit2: put spaces after the b before the ) so it wouldn't be an emoji (it's not in the code)

This post was edited by cappichino on Feb 11 2020 07:07pm
Member
Posts: 308
Joined: Jun 7 2019
Gold: 13.37
Feb 13 2020 06:26pm
You could have formatted the code by using codeblocks
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll