Thursday, May 10, 2007

Lesson 5: Swimming The Keystroke

By this time you've probably started to out pace these lessons or at least come across problems you've had trouble solving when it comes to entering text. Some windows just don't cooperate...at all. Well, like ancient archers who picked certain arrows for certain jobs, you can do the same with keystrokes methods. So far, I've covered 'outp' with quoted text and with strings but there are two other ways as well: the 'key' function and QM key-codes (QM uses special characters to represent the special keys like Alt, Ctl, Shift, etc. (well, not 'etc' that's just one of those Latin things; it's not a keyboard thing)). Let's start with the apostrophe first.

Look at the QM Toolbar that starts up with the Editor; the second icon opens a dialog to show you all the special characters. You can start using these very easily by invoking the function with an apostrophe like this ' .

Note: I'll be taking many of the examples directly out of the QM Help. BTW: you can easily access the help documentation and go to the function you are curious about by just placing your cursor on the function and hitting F1; often times there is a very well documented article on the function (sometimes the help text appears in the output window below the editor instead).
'CSf A{ec} Wd ;;Ctrl+Shift+F, Alt+E+C, Win+D note: the Alt key is released after the c key
'SnewVSyork ;;type "New York" using QM key codes

The apostrophe is a quick and dirty way of getting text to type rather than pasting text via the 'outp' function. The 'key' function works similarly but has more flexibility. Here is how those examples would look when using 'key'.
key CSf A{ec} Wd ;;Ctrl+Shift+F, Alt+E+C, Win+D note: the Alt key is released after the c key
key SnewVSyork ;;type "New York" using QM key codes

Yeah I know but that was just to show you how it looks; now let's really get into it.
key (VK_MEDIA_PLAY_PAUSE) ;;Mimics hitting the Play/Pause button
key a (0.5) b ;;a waits 0.5 second b

Here's another way of doing multiple keystrokes while holding down modifier keys. You can put all kinds of things inside that block; not sure what other types of things you would want to though.
key+ CS
lef
key- SC
'Key' will also let you feed the contents of a string variable into it. So, you can easily create the variable value from any other method and then you can have 'key' type it in. This works especially well for a telnet program I use that won't allow direct pasting into the command line.
key _s
Now usually, you won't have to go to such drastic measures just to input some text but if you need it (like in my telnet program) you've got it. Granted, it's not particularly strong me (mĀ), but when you gotta have it, you gotta have it.

So have at it and I'll see you next time cause the hook always brings you back.

1 comment:

Unknown said...

The key() function is different than all other. With other functions,

func _s

means that _s is a variable. In case of key() function, variables must be enclosed:

key (_s)

Everything that is not enclosed in () or "" is interpreted as key codes. Parts enclosed in "" are interpreted as simple text.

key keycodes (variable) "text"