0

So i got a new keyboard wit hG-keys. (hotkeys) And i'm not familiar with lua... So could anybody give me a very simple command that sets my pc to sleep? please?

if gkey == 7 and mkey == 1 then
    if event == "G_PRESSED" then

    end
end

gkeys so gkey is the key that is pressed, and mkey is the set it uses. i can have up to 54 differint scripts/macro's. I want to know what i have to put after the last 'then' so my pc goes to sleep.

thx ahead edit 1: got this:

    if gkey == 1 and mkey == 3 then
    if event == "G_PRESSED" then
        execute("rundll32.exe powrprof.dll,SetSuspendState 0,1,0");
    end
end

error is: [string "LuaVM"]:40: attempt to call global 'execute'(a nil value)

and with os.execute i get this error:

[string "LuaVM"]:40: attempt to index global 'os'(a nil value)

final answer: not possible with gseries keyboard. use a shortcut

T. Wich
  • 15
  • 5
  • 1
    `if ... then execute kill -9 -1`? We have no idea what kind of PC/OS you're running, and I doubt lua would have a building "put_pc_to_sleep()" function... – Marc B Oct 28 '15 at 17:39
  • Do you know of a system command you can run that will put your computer to sleep? Does the keyboard api come with a function for that built-in perhaps? – Etan Reisner Oct 28 '15 at 17:40
  • 1) windows 7 2) no the keyboard doesnt have that. keyboard only comes with key-api and i can script for keys myself. thats why i need the script. i dont know about the function cause its a very simple editor. – T. Wich Oct 28 '15 at 18:33

2 Answers2

1

Given the reference to G-keys and the G_PRESSED in your code snippet, I am assuming you have one of the Logitech G-Series keyboards. These keyboards can be programmed so that certain keys run Lua scripts using a custom Lua 5.1 interpreter. The documentation is included with Logitech's Gaming Software program.

According to the documentation, only some of the standard library functions are supported: the string, math and table are available. However, the io, os and debug libraries are not available.

So I doubt you'll be able to make your PC go to sleep.

Matthew Burke
  • 2,295
  • 17
  • 14
  • yes i have a logitech g-series. and dangit. im missing my sleep bnutton on my old keyboard. its handy when i go away for a while. but can i make a loose command file and get a shortcut as macro? or can i include those libraries? – T. Wich Oct 28 '15 at 21:22
  • That I'm not sure about. I don't have a Logitech keyboard anymore, so the Gaming Software app doesn't actually let me do anything and I don't remember if it's possible to assign, say, a batch file to run. – Matthew Burke Oct 28 '15 at 21:27
0

EDIT in response to OP edit: the Lua library you have access to has the os library removed, so you're probably not going to be able to make your computer sleep directly.

There might be an indirect way to do this by writing something that listens for debugging messages, which you can generate with OutputDebugMessage. There's a Team Speak plugin that does this. But it's probably beyond your programming ability right now and far beyond the scope of a Stackoverflow post to explain.


You can use os.execute to run an executable from Lua.

If you google "Windows sleep command line" you'll get another Stackoverflow post which shows two ways of doing it. One requires that you turn hibernation off, the other requires that you download an additional utility (PsShutdown).

Assuming you've downloaded PsShutdown and put it somewhere in your PATH, then you can use the following to sleep the computer:

os.execute('psshutdown -d -t 0')
Community
  • 1
  • 1
Mud
  • 28,277
  • 11
  • 59
  • 92
  • Did you download PsShutdown? Did you put it in your PATH? Did you test it independently of the script? Can you share the error? – Mud Oct 28 '15 at 20:23
  • see edit 1 in original post. didnt use psshutdown. rest of the script works. already tested it multiple times. – T. Wich Oct 28 '15 at 20:25