DashingStrike / Automato

Automato LUA-based scripting engine
4 stars 2 forks source link

Hotkey functionality #3

Open kwyd opened 9 years ago

kwyd commented 9 years ago

Is it possible to emulate hotkeys?

I'd like to call specific functions when specific keys are pressed.

thanks for your hard work

Jimbly commented 9 years ago

No, there is no current hotkey functionality (other than specifically checking if shift or ctrl are held via polling). The design philosophy for ATITD was that you should always be able to be typing and chatting while a macro was running, so hotkeys just didn't make sense. For more general use in other programs, though, hotkeys would be useful, so it is something I'd like to do at some point. If you don't need the target app in focus, it would be very easy to add (similar to having buttons in the UI, checking for keypresses in the Automato window is very easy and supported by the underlying UI library, I'd just have to expose it to LUA), though if you need them to trigger while target app has focus, it's a bit more work (have to do OS-level stuff to sniff key events going to other programs or register global hotkeys).

kwyd commented 9 years ago

Basically, i'd like to write an interface client, so i can do things like browse/manage beetles with numpad hotkeys, instead of having to click those tiny little arrows.

if i could check for keypresses like END/PGDN etc, it seems easy to map keys to click the UI buttons with whichever task i was doing.

it doesn't exactly mesh with the typing while automated things happen design, so i'm just looking for workarounds, if any exist.

Thank you for your quick response and attention =)

Jimbly commented 9 years ago

Well, if that would work while the ATITD window is not in focus (focus on the Automato window and all keypresses are going there and just sending mouse clicks to the background ATITD window), then just exposing the keypress UI functions would work (could do that tonight, should literally be a few minutes (plus testing, and remembering how to sign and distribute a build..;)). If you want to mix-and match yourself clicking on things and using hotkeys, than we need something more involved.

kwyd commented 9 years ago

the only issue i see with that (which would work fine otherwise) is switching back to focus automato after mouseclicking the client. or can it send mouseclicks w/o losing focus?

i want something like: numpad END clicks <- left arrow, PGDN clicks -> right arrow using predefined coords.

i don't need to be able to do any ancillary tasks, as i'll be focused on the terrarium =)

Jimbly commented 9 years ago

It can send mouse clicks without losing focus (srClickMouseNoMove sends a click event to a window without changing focus, which generally works fine for ATITD, srClickMouse sends more of an os-level mouse click, which will move the cursor and change focus/etc, just as a real mouse click would). I'll try adding the UI keyboard input stuff in the next day or two, and hopefully that will work for you =).

kwyd commented 9 years ago

srClickMouseNoMove sounds like just what i want.

thanks again for your help

Jimbly commented 9 years ago

Automato v2.07 is now released, which should let you call lsKeyDownHit("KP_1") to see if the user pressed the End key on the keypad. There is an example in Examples/UITest.lua. It's best used with a on-screen button, e.g. if lsButtonText(.., "Next (End)") or lsKeyDownHit("KP_1") then do it.

Jimbly commented 9 years ago

Details at in the scripting reference with list of key names here.

kwyd commented 9 years ago

looks good, i'll go play with it now.

Many thanks!