3

I usually use java.awt.Robot when I want to simulate keyboard and mouse entries and it work very well.

Recently I heard of another language, Lua, and I try it. I wrote some little programs that work well, but now I'm tying to simulate a keyboard like in java but I can't make it work.

The most frustrating part is that I find example that use a PressAndReleaseKey('someKey') function in Lua with google, and these codes seems to require no library, however I can't make this function work (they also seems to be always related to logitech so maybe it's only usable within logitech drivers?). So I'm not sure it is what I'm searching for.

So, in short, my question is: How can I simulate a keyboard entry with a Lua program?

For example, if I type in my terminal

lua test.lua

with this file been like that:

while(true) do
     thefunctionIsearch('a')
end

then the program is supposed to type the letter 'a' infinitely.

I am on Linux (Ubuntu) if it something.

1 Answer 1

3

these codes seems to require no library

It can't be done without a additional libraries. It can't be done in C without external libraries, and Lua's standard library is implemented entirely in terms of C's standard library.

they also seems to be always related to logitech so maybe it's only usable within logitech drivers

Logitech has keyboards scriptable in Lua, so you're almost certainly seeing a Logitech-specific extension to Lua that's not available in vanilla Lua.

How can I simulate a keyboard entry with a LUA program?

Find or write a module that does it. If you know C, it's very straightforward.

Alternatively, if you can find a shared library that does it for Linux, you could use LuaJIT's FFI to interface with that library directly without having to find/write a module.

Sign up to request clarification or add additional context in comments.

3 Comments

So, if I want to simulate my keyboard entry with LUA, I must write a code in C and call it in my LUA function? I have never mix different language but I guess it's a good time to begin, I will search how to do that thanks. Does it change something to write it in C or in java? (I already have my java methods functionning)
I just read that LuaJIT is faster than lua so I think I will migrate to LuaJIT (So I will use FFI and C). Thanks again.
Yeah, Lua is C and it's API is C, so writing Lua modules in C is by far the easiest path. Using the FFI is a bit more awkward than linking against a C library and using it from C, but if you can do the latter you should probably be able to figure out the former.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.