Jump to content




How to virtually type a key using Lua


  • You cannot reply to this topic
8 replies to this topic

#1 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 28 September 2016 - 07:23 PM

Hi Guys!

I wanted to virtually type a key using Lua so i can type "h" on a computer and using wireless modems to type "h" on the actual PC.

i tried this:
p1 = "paste"
p2 = "h"
p3 = nil
os.queueEvent("paste", p1, p2, p3)

And it just typed "paste"

Please Help

Thanks!

#2 supernicejohn

  • Members
  • 98 posts
  • LocationSweden

Posted 28 September 2016 - 08:02 PM

Wouldn't "key" event be better? or just "char" if it's only for typing. Unsure where the pullEvent is, or if it's something else. Let's hope someone knows a bit more about these things than I do...

#3 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 28 September 2016 - 08:23 PM

Hmmm. the key event will just say the key number. Did not try char yet. Im trying it now

EDIT: I did os.queueEvent("char", "h") and it wrote h, Thanks!

EDIT2: How do i virtually make it press the enter key, ctrl, backspace, etc.

Edited by houseofkraft, 28 September 2016 - 08:29 PM.


#4 valithor

  • Members
  • 1,053 posts

Posted 28 September 2016 - 08:26 PM

It printed "paste" because you passed the following arguments to os.queueEvent: "paste", "paste", "h", nil

The first argument to os.queueEvent is the event type, for the paste event the second is what was actually in the clipboard when ctrl+v was pressed, so that is where the "h" should be.

os.queueEvent("paste","h")

Although that would probably work I would personally use the char and key event (I would queue both solely because many programs use both events for different things).

str = "hello"
for letter in string.gmatch(".") do
  os.queueEvent("char",letter)
  os.queueEvent("key", keys[letter],false)
end

Keep in mind though that this would break if there was more than 120ish letters in the string.

edit:

Luckily all of the built in scripts support char events that are more than a single char (whether or not this was intentional).

example:
str = "hello"
os.queueEvent("char",str,false)

Edited by valithor, 28 September 2016 - 08:29 PM.


#5 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 28 September 2016 - 08:49 PM

Yeah ik, but how do i make it register backspaces, spaces, etc.

#6 supernicejohn

  • Members
  • 98 posts
  • LocationSweden

Posted 28 September 2016 - 08:50 PM

"It printed "paste" because you passed the following arguments to os.queueEvent: "paste", "paste", "h", nil". Missed that! :)
For backspace and other keys, the key event would likely work. Not sure what the implementation is but that's the only thing I can think of.

#7 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 28 September 2016 - 08:56 PM

How could i use the key event to do that? I thought it just says numbers for each key

#8 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 September 2016 - 09:07 PM

os.queueEvent( "key", keys.backspace )
Source

Edited by KingofGamesYami, 28 September 2016 - 09:07 PM.


#9 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 29 September 2016 - 08:12 PM

Thanks!

Off to coding!

Edited by houseofkraft, 29 September 2016 - 08:12 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users