First there is a problem with "input.KeyGetState()" the first fix/change for the upcomming "2.01" release.
It's not always returning the right flags.
I'll send you a "test" version so you can get around the problem till the next release.
There is actually three states/flags of output.
The core of it is two Win API calls, "GetAsyncKeyState()" and "GetKeyState()".
It was necessary to combine two because of some problem (undocumented?) where GAKS doesn't
properly return the flags for some keys.
Form
input lib doc:
Quote:
state = input.KeyGetState(keycode)
Get key state by virtual key code. 0 means key up, 1 key is down, 2 key was down since last call.
The 2 case is somewhat unpredictable, so it’s generally better to look at the return as being 0 or 1.
You probably need to just change turn your
into "not equals zero" tests like:
Code:
if stateNO ~= 0 then
Note in essence here by using
input.KeyGetState() we're basically doing global "hotkeys" semantically.
There is not way other then this to this kind of thing in MM yet.
I considered adding "registered" hotkeys which are normally "event driven" things.
Maybe a good way would be a gueue to be polled to get the last "hotkey" presses.
If you just want command/control keys from input in the MM console you can use "console.GetKey()".
This is buffered input so you won't miss any presses. Maybe you want gobal hotkeys, just saying..
I'm not sure of your code there.
You'll probably want to keep track of the last key down state and compare it to it's current state in your polling.
Maybe something like this:
Code:
-- Someplace local to the module, or globally
-- Auto looting switch
gbLootOn = false -- Or 'true' if it should be on by default..
gLastF3State = -1 -- To keep track of physical key state
-- Hotkey poller
function PollHotkeys()
-- Watching the "F3" key
local KeyState = 0
if (input.KeyGetState(input.VK_F3) > 0) then KeyState = 1 end
if (gLastF3State ~= KeyState) then
-- On captured key press, toggle the true/false state of the flag
if (KeyState > 0) then gbLootOn = not gbLootOn end
gLastF3State = KeyState
end
-- More hot keys here..
end
By saving a "last" state of the keys of interest we can get clean "debounced" key inputs.
-- Then in your code for looting
if gbLootOn then
DoAutoLootCycle()
end
...
Note in a lot of the examples, etc., I use sort of a "Hungarian notation".
See:
http://en.wikipedia.org/wiki/Hungarian_notation I sometimes prefix with 'g' to indicate "global", 'b' for "boolean" values, etc.