views:

182

answers:

2

I have an application that has 'macro' capabilities. When I map some keys on the keyboard to perform the 'macro', I can also have it launch vbscript instead.

What i'd like to try and do is within my vbscript figure out what keys were used in order to launch the script. Is it posible to do this? Could there be a way in vbscript to figure out what keys were last touched on the keyboard and then I could apply my logic.

The purpose of doing this is to keep the code in a single .vb file instead of several seperate .vb script files(one for each keyboard mapping, possible 3-4). Obviously we are looking to just maintain 1 file instead of multiple files with essentially the same code in each one.

I am leaning towards the idea that this is not possible, but i figured this would be a worthy question for the masses of StackOverflow. Thanks for the help everyone!

+2  A: 

What you are asking for is not possible.

Can you change your VBScript to accept parameters and then call it with a different parameter based on which hotkey was selected?

aphoria
I believe you are correct.My plan is to use multiple vbscript mapped macros that all call a "main" vbscript file with an input parameter to help the main vbscript determine what to do. For example, scriptA is launched when a key is pressed, all script A does is create the wsscript.shell object and launch the main vbscript file passing it value "1". the main vbscript will grab that parameter and use it in a case statement to detemine what to do. Thanks for your help aphoria.
Zombie8
Thanks for accepting my answer. Is there a reason you can't just call your main script with the parameter when you press the key?
aphoria
A: 

I agree with aphoria, the only way to make something like this possible is if your keyboard mapping software allows you to assign a script/command with parameters/arguments. For example if you used

c:\Temp\something.vbs

then you would change this to

%WINDIR%\system32\wscript.exe c:\temp\something.vbs "Ctrl-Alt-R"

Then in your vbscript code you could collect the argument using the wscript.Arguments object collection to do actions based on what argument/parameter was passed. See the following two links for more info:

http://msdn.microsoft.com/en-us/library/z2b05k8s(VS.85).aspx http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0915.mspx

mrTomahawk