- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
g510 Script Help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-27-2012 01:27 AM
Hello,
I am trying to create a script that will press the m key, delay for a random amount of time, release the key, then delay for another amount of time and make it loop for however many times I put for i.
this is what I have, but it doesn't seem to work
function OnEvent(event, arg)
randomsleep1=math.random(335, 798)
randomsleep2=math.random(35489, 42784)
i=5
if (event == "G_PRESSED" and arg == "18") then
loop=i
PressKey("m")
Sleep(randomsleep1)
ReleaseKey("m")
Sleep(randomsleep2)
end
end
end
Solved! Go to Solution.
Re: g510 Script Help
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-27-2012 02:42 AM - edited 04-27-2012 03:00 AM
the arg variable is an integer! .. so it should be arg == 18
this should work: (maybe use some smaller rnd-sleeps for testing)
ClearLog();OutputLogMessage("Script loaded!\n")
i=5
function OnEvent(event, arg)
--OutputLogMessage("event = %s, arg = %s\n", event, arg);
if (event == "G_PRESSED" and arg == 18) then
for c = 1,i do
randomsleep1=math.random(335, 798)
randomsleep2=math.random(35489, 42784)
--OutputLogMessage(c.."\n")
PressKey("m")
Sleep(randomsleep1)
ReleaseKey("m")
Sleep(randomsleep2)
end
end
end
--eofNOTE: during the loop (no other G-Keys will be recoginzed BY SCRIPT, since OnEvent() is still running and cannot be called again
Re: g510 Script Help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-27-2012 07:54 PM
So if I wanted to stop the script instantly, do I just press G18 again? or would more need to be added?
Re: g510 Script Help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-27-2012 08:22 PM
Without the use of polling, you could not do that with a script. The eastiest option is to check for modifiers to stop it.
Re: g510 Script Help
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-27-2012 08:49 PM - edited 04-27-2012 08:50 PM
Hmmm, how about if the Active Profile isn't the 'focus" anymore? Like alt-tabbing to a different program. Does that stop the script automatically?
Re: g510 Script Help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-28-2012 07:29 AM
It would, but not the most ideal.
Re: g510 Script Help
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-28-2012 07:58 AM - edited 04-28-2012 03:21 PM
Here is an example of using the above script modified to stop if a modifier is pressed. terminateKey is assigned to the modifier which will stop the script. In this case, it's right-ctrl, but can be modified to what ever you want.
ClearLog();OutputLogMessage("Script loaded!\n")
i=5
minDelay = 16
terminateKey = "rctrl"
function OnEvent(event, arg)
--OutputLogMessage("event = %s, arg = %s\n", event, arg);
if (event == "G_PRESSED" and arg == 18) then
RandomizedDelayKeyPress("m")
end
end
function RandomizedDelayKeyPress(key)
for c = 1,i do
randomsleep1=math.random(335, 798)
randomsleep2=math.random(35489, 42784)
PressKey(key)
local ret = Wait(randomsleep1, terminateKey)
ReleaseKey(key)
if ret == "aborted" then
return
end
ret = Wait(randomsleep2, terminateKey)
if ret == "aborted" then
return
end
end
end
function Wait(time, abortModifier)
local ts = GetRunningTime()
while GetRunningTime() - ts < time do
if IsModifierPressed(abortModifier) then
return "aborted"
end
Sleep(minDelay)
end
return true
end
--eof
Re: g510 Script Help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-28-2012 11:42 AM
Thank you very much for educating me ![]()
