Saving Keys to press as variables

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Saving Keys to press as variables

Post by Phil Pendlebury » Tue Feb 20, 2007 5:00 pm

Hi there,

I wrote a script that defines some keys to be pressed in my main script.

I won't go into detail now but I have come across a problem which I'm sure will be quite easy for more experienced users to solve.

Example:

My main script requires the pressing of the "k" key to open a dialog. Some users already have the "k" key assigned to something else in the application so I give them the option to change the key. and then store their preferred key as a variable.

So:

Send>k

becomes (as an example)

Let>variable_set_by_user=k
Send>%variable_set_by_user%

Now to the problem:

Alot (in fact most) of the key modifiers used in the application are already single keys.

So I need a way to assign "Press" to variables.

I wrote the dialog with a drop down list, allowing them to choose ALT, CTRL, SHIFT etc.

but when sending the variable that contains for example "CTRL" it will not work...

Example

Let>variable_set_by_user=k
Let>key_set_by_user=CTRL

Press %key_set_by_user%
Send>%variable_set_by_user%
Release %key_set_by_user%

Is there a way to store keys such as Control, Shift, Alt etc. into variables?

Sorry if this post seemed long winded but I thought all info may be required.

Thank you.
Phil Pendlebury - Linktree

fightcancer
Macro Veteran
Posts: 239
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Tue Feb 20, 2007 5:28 pm

I'm much less experienced than most, but I'm not sure if you saw this note from the help file under Press:
There have been reports that Press CTRL, Press SHIFT and Press ALT sometimes fail when running Macro Scheduler under a Citrix environment. This can be fixed by setting SK_LEGACY to 1 prior to issuing these keystroke commands. Some DOS applications also need SK_LEGACY set to 1.

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Tue Feb 20, 2007 6:34 pm

Yes I did see that thanks but it's not relevant to me.

Just try this:

Let>modkey=ALT
Let>key=F

Press %modkey%
Send>%key%

etc. and see if it works for you.

:-)

I will give it another try though.
Phil Pendlebury - Linktree

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 20, 2007 7:10 pm

As you have noted Press doesn't accept a variable. Press isn't a command in it's own right. Each Press ... command is a separate command.

Two options:

1. Create a subroutine for each Press ... command you want to use and branch to it based on the user's selection.

2. Do this:

WriteLn>%SCRIPT_DIR%\temp.scp,r,Press %modkey%
Macro>%SCRIPT_DIR%\temp.scp
DeleteFile>%SCRIPT_DIR%\temp.scp
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Tue Feb 20, 2007 7:17 pm

Thank you Marcus. I will looking at option 1 I think.

You saved me hours of trial and error there as I was thinking I had done something wrong.

:-)
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts