Is there a way to send keyboard keys to other windows?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
keithglong
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 348
Joined: Sun Jul 03, 2011 2:04 am

Is there a way to send keyboard keys to other windows?

Post by keithglong » Tue Sep 27, 2011 10:12 am

Hello,

This might be a dumb question, but is there a way in LiveCode to simulate sending keyboard keys to non-LiveCode applications/windows? For example, if I am running Firefox and want to send a CTRL-T in order to open a new tab, is there a way that I can simulate the CTRL and T being pressed and then send it to a particular instance of a Firefox Window accordingly?

Thanks,

- Boo

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Is there a way to send keyboard keys to other windows?

Post by sturgis » Tue Sep 27, 2011 7:36 pm

For a test run to see how it could be done, make a simple stack with a button and a field.
(disclaimer- I don't know vbscript very well, so anything more complex than this would require research)
In the field put the following:
Dim Wsh
Set Wsh = CreateObject("Wscript.Shell")
Wsh.AppActivate "Firefox" -- activate firefox so that it has focus
Wsh.SendKeys "^t" -- send the keys. the ^ stands for control in this case. % is alt, + is shift.
For the button script, put:

Code: Select all

on mouseUp
   do field 1 as "vbscript"
end mouseUp
Assuming firefox is already open, clicking the button should pop a new tab up. On this same note, its very possible that firefox has vbscript hooks so it might be possible to talk to it in a more direct way. But as I said, I don't know as much about vbscript as I would like.

Post Reply