Solved How do you programming keyboard shortcuts

December 14, 2012 at 10:02:43
Specs: Windows XP

would like to write, or have an MS-DOS script (or C++ or JAva progran) called tab which,
when executed, implements what the the tab keystroke would do in a specified active program. The program, I guess, would be a parameter of the script.

I would like to have such scripts for other keys, such as enter to select an item or
ctrl + c to copy the content of a cell into the cut/paste buffer, as well. In short,
I want to be able to surf through a program with a script, do anything I might dream of doing with a sequence of keystrokes from my keyboard.

I suspect that I have not presented you with a well-defined idea. If you could correct this, I guess tell me what I'm doing, I would be for grateful for that too. If such a task is better implemented in C++ or Java then please, let me know too, and please provide references. If there are obstacles then please point out one or two of them. I'm motivated and willing to work, just need some direction.

Thanks and many kind regards, Randy


See More: How do you programming keyboard shortcuts

Report •


#1
December 14, 2012 at 14:45:16
✔ Best Answer

Might be worth looking at AutoHotkey. You can program keys with this, or if necessary do things with screen locations. Problem with the latter is it is only any good if you can be certain nothing will move. It can also run from a batch file, or batch files can run AutoHotKey scripts:

http://www.autohotkey.com/

As far as I know it is still free. I'm no programmer so you might be able to do a lot more with it than I do.

Always pop back and let us know the outcome - thanks


Report •

#2
December 14, 2012 at 20:06:41

I wrote this for my own benefit some time ago. It sounds similar. It is simply a "front-end" for batch to use sendkeys, but it uses a "script" file. It might be adapted for interactive use, but I just wanted to automate some things for batch.
Unfort., it is in vis-basic, and I haven't tried to port it to vbs, so you'll need a compiler unles you or I convert in the meantime. I won't post the source-code, until you ask for it. Here is the lengthy "help" describing the program's application:

Usage: sendkey [path+file]
If the path/filename is not given, then a default name of "control" will be tried.
The given file provides the script that drives the program.
The file's format consists of 3 leading or "header" elements, followed by
any number of data elements. Any element, whether header or data, is optional,
none are required, BUT you must reserve an empty spot for each header element.
Elements can be separated by either comma or newline (each on its own line).
- CONTROL/SCRIPT FILE FORMAT -
HEADER:
1) program to start/run, incl. any commandline data: f/e: NOTEPAD SENDKEY.HLP
2) program window style: 0: hidden, 1: normal 2: icon 3: maximized
note: if window-style is zero, the window cannot be accessed for sendkey
3) title of window to which keys will be sent, matches any window up to
length of string given so be specific enough to get the right one.
f/e: sendkey - Notepad
DATA (SCRIPT):
4...) DATA: keystrokes and delays, mixed/assorted as needed:
Any unquoted integer is interpreted as a DELAY element as no. of milliseconds
Keystroke(s): Any quoted item or non-integer item (quoted or not) is interpreted
as a keystroke-string to send. For more detail, refer to "KEYS" below.
Any item that contains a comma, be sure to enclose it in dbl quotes, like: ","
To send a dbl quote, enclose it in braces, like: {"}
Note: Some combinations, such as and especially, shift+tab, or: +{tab} will
fail unless quoted. To send a shifttab: "+{tab}"

Example: say you want to send the word "testing", then ENTER (newline),
then "line, two", a quoted "goodbye", then a 1-sec. delay, then alt-e,a into
Notepad, here's script in comma-separated elements format:
notepad,1,Untitled - Note,testing,{enter},"line, two",{ENTER},{"},goodbye,{"},400,%e,a

or, alternative to commas, this script uses newlines:
notepad
1
Untitled - note
testing
{enter}
"line, two"
{enter}
{"}
goodbye
{"}
400
%e
a

Or for easier interpretation / readability, you can mix the two formats,
&/or add quotes, and when there are no delays and no commas, you can combine
keystrokes into one string:
notepad,1,"Untitled - Notepad"
"testing"{enter}
"line, two"
{ENTER}{"}goodbye{"}
400
%ea

(A sample file similar to this is included with the documentation: It does
write to a file "sendkey.xxx" in windows' temp directory
and also puts the content onto the clipboard using ctrl-C. The sample is called
"sendkey.tst" and demonstrates various keystrokes and actions.)

KEYS:
Nothing is sent into the window except exactly what you specify in the list.
When the end of the list is reached, control reverts to manual (user interactive).
"regular" keys are standard printable keys other than (){}[]^%+
Specify any regular keys like (examples): A, AB, AB76, A:B, A/?X&
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses ( )
have special meanings to SendKeys. To specify one of these characters,
enclose it within braces. For example, to specify the plus sign, use {+}.
To send brace characters, use {{} and {}}.
Brackets ([ ]) must also be enclosed in braces as well, because some other
applications use them.

To specify characters that aren't displayed when you press a key (such as
ENTER or TAB) and keys that represent actions rather than characters, use the
following table: (note, these are NOT case sensitive)

Key Code
--------------------------------
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER} or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS {INSERT}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1..F16 {F1}..{F16}
To specify keys combined with any combination of the SHIFT, CTRL, and ALT,
precede the regular key code with one or more of the following codes:
+ = SHIFT, ^ = CTRL, % = ALT. F/e: %{f4} for the end-pgm seq ALT-F4

To specify that any combination of SHIFT, CTRL, and ALT should be held down
while several other keys are pressed, enclose the code for those keys in
parentheses.
F/e, to send SHIFT-EC (SHIFT held down while E and C are pressed), use: +(EC)
To specify to hold down SHIFT while E is pressed, followed by C without SHIFT,
use: +EC
To specify repeating keys, use the form: {key number}. You must put a space
between key and number. For example, {LEFT 42} means press the LEFT ARROW key
42 times; {h 10} means press h 10 times.

SendKeys can't send keystrokes to an application that's not designed to run in
Windows. Sendkeys can't send the PRINT SCREEN (PRTSC) key to any application.
================== end "help"
If you want to download the source + exe (and help):
http://pages.suddenlink.net/kitpack...
and select "sendkey.zip"
ps: my experience with "macro recorder" programs, using the mouse, has been very undependable. I gave up on those, which is why I wrote this one. The screens/windows are too dynamic, you miss the target as much or more than you hit it. This also implies much patience learning to avoid mouse-activity in favor of kbd, and some programs seem to "stick" until you use that friggen mouse click (infernal device!).


Report •

#3
December 18, 2012 at 05:59:25

I'm up and running with autohotkey, which seems to do everything I need and much more. Yes, autohot key is still free and written in C++, which put it in my backyard.

Thanks so much for our interest and help. Randy


Report •

Related Solutions

#4
December 18, 2012 at 07:48:59

Good to hear it. Thx for popping back to let us know. If you care to mark an input as Best Answer then this thread will show as solved.

Always pop back and let us know the outcome - thanks


Report •


Ask Question