Simulate Keypress

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
shaky
Posts: 8
Joined: Sun Aug 25, 2013 12:45 pm

Simulate Keypress

Post by shaky » Sun Aug 25, 2013 1:01 pm

hey, I've been trying to work out this problem, if someone could help me would be much appreciated

I came across this
on rawKeyDown theKeyNumber
put theKeyNumber
pass rawKeyDown
end rawKeyDown
(which gives me the key number for the designated key)

so I tried the script below hoping it would work but I guess im doing it wrong.
on mouseUp
rawKeyDown 65289 ( but just gives error (button "Button": execution error at line 2 (Handler: can't find handler) near "rawKeyDown", char 1)
end mouseUp

but what Im trying to do is when I click the button in my program it launches a exe file, then I need to simulate a key press so it will do a few tasks like a macro.
some of the keys I need to work are alt, (65513) and tab (65289) for example.
and if possible to have the code press alt & tab at same time.
im trying to work through the livecode lessons and university at the moment but any help with this would help a lot.

Thanks

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Simulate Keypress

Post by Mark » Sun Aug 25, 2013 1:08 pm

Hi,

Is that exe file a LiveCode standalone? If not, what is it?

You might write a VBScript and use the SendKeys method to emulate a keydown.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

shaky
Posts: 8
Joined: Sun Aug 25, 2013 12:45 pm

Re: Simulate Keypress

Post by shaky » Sun Aug 25, 2013 1:22 pm

its actually Microsoft publisher, I need it to load the program which I can get to do, then I need it to sendkeys like I did in the past on visual basic to auto complete a few tasks.
kinda hoped to be able to do it in livecode.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Simulate Keypress

Post by Mark » Sun Aug 25, 2013 3:25 pm

Hi,

Yes, you can do that with VBScript. LiveCode can execute your VBScript with the do command.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

shaky
Posts: 8
Joined: Sun Aug 25, 2013 12:45 pm

Re: Simulate Keypress

Post by shaky » Sun Aug 25, 2013 5:09 pm

thx for the reply mark, I will need to read up on it.
do you mean I need to save the vbscript to a file and execute it from inside livecode, or is there a way to insert vbscript directly into livecode.
sorry total noob here but trying my best to learn livecode ;)

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Simulate Keypress

Post by Mark » Sun Aug 25, 2013 5:14 pm

Hi,

Look up the "do" command in the dictionary. You can use it to execute VBScript directly. Only in special cases, if you create new objects or routines, you need to create a separate file.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply