Solved why does my batchfile code fail ?

Gateway Atxstf
September 16, 2016 at 03:07:55
Specs: Windows 10, 4Gb
batchfile to send keystrokes
I want to substitute a mouse click for a keypress. It is CTRL Prntscrn that I want to effect. But the code

Send("^{PRINTSCREEN}")

by itself in a batchfile does not have the same effect as pressing the keys.
Why not ?
OR
what code WILL produce the required effect ?

Basty


See More: why does my batchfile code fail ?

Report •


✔ Best Answer
January 18, 2017 at 06:52:47
It is now long ago that I found a PERFECT solution in using a quite simple script in Macro Express. SOLVED.

Basty



#1
September 16, 2016 at 04:31:41
I haven't tried that particular combination but Autohotkey is good and straigtforward for that sort of thing:

https://autohotkey.com/

It can also call up a batch file if required.

Always pop back and let us know the outcome - thanks


Report •

#2
September 16, 2016 at 04:38:10
I have used Autohotkey a lot. But when I researched this on the Web, the SEND procedure seemed much simpler, so I thought I'd see if this could be an advance on Autohotkeys. But I have not found an intelligible set of COMPLETE instructions on how to implement SEND or Sendkeys

Basty


Report •

#3
September 16, 2016 at 05:48:28
SEND has never been a command in any version of Windows. Both VBScript and PowerShell have options to generate key input for other applications, and PowerShell technically has access to .NET's UI Automation, but CMD does not.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
September 16, 2016 at 05:56:11
Since it is such a 'trivial' procedure [one hot-keystroke] - can you illustrate the use of VBScript or Powershell to achieve the conversion of THE EFFECT of pressing a hotkey to that of a clicking a mouse ?

Basty


Report •

#5
September 16, 2016 at 06:05:13
I can't feasibly provide a working example at the moment, so you're probably better off searching for SendKey examples on Google.

EDIT: Oh yeah, scripts can't intercept and block user input, since that requires the use of filter drivers or Win32 input hooks. What you're really looking for is AutoHotkey. You're asking about creating AutoHotkey in a scripting language, but that's not actually going to happen.

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#6
September 16, 2016 at 08:34:10
In Autohotkey it seems that this should do it:

Send {LCtrl}{PrintScreen}

Here's the full info:
https://autohotkey.com/docs/command...

EDIT:
As you probably know, you can compile AHK files to EXE if you don't want the AutoHotKey program on board.

Always pop back and let us know the outcome - thanks

message edited by Derek


Report •

#7
September 16, 2016 at 17:50:24
So I put your code into a text file and called it printscreen.ahk, then created a batchfile with the following code

Start "" "C:\Program Files\Autohotkey\Autohotkey.exe" "C:\Data\Autohotkey\Printscreen.ahk"

which works for other applications but apparently NOT for printscreen ....

Basty


Report •

#8
September 16, 2016 at 20:44:27
I've worked some with the sendkeys (cause I try to automate things) in both vbs and visual basic. Unfortunately, PRTSC is about the only key that sendkeys will not send.
Here's my "help" for the vbscript version (included all, but the last line is the clincher):
Sendkey.vbs - sendkey.hlp
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 are separated by 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
note: this can be left blank if you know the program will already be running
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
recommend 1 or 3
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
note: this is taken from the blue title-bar of the window you want to work in. Only needs to match up to what you need to qualify it against other open window's titles.
DATA (SCRIPT):
4...) DATA: keystrokes and delays, mixed/assorted as needed:
Any unquoted integer is interpreted as a DELAY element in 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: "test,this"
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 (Select
All) into Notepad, this would be the content of the send-script file "test.sks":
notepad
1
Untitled - Note
testing
{enter}
"line, two"
{ENTER}
{"}
goodbye
{"}
400
%e
a

Your batch can build the script file, since it's text, and then it can execute
the file (f/e: TEST.sks): cscript sendkey.vbs test.sks
NOTE: if you use batch to build the send-script, and you intend to send ALT
keys, be sure to double up the percents, f/e: >>TEST echo %%f (to get ALT-F)
(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.
----------------
(most of the KEYS section is verbatim from the help files.)
There's probably a better way to achieve your goal than using PRTSC anyway, or at least a possible way. I think this approach is spent. Sendkeys can collect text from a window using alt-E, S to "select all", but your batch will have to sort out the resulting mess if it's a web-page, word document, etc. Best thing is if you can clue us in to what information you want to extract and from what application or utility.

message edited by nbrane


Report •

#9
September 16, 2016 at 21:17:51
All I want to do is convert the hotkey CTRL-PrntSc to a mouse click - I thought that a batchfile would be the obvious way to do this.

The effect of CTRL Printscreen is to trigger (through GreenShot) the conversion of the mouse cursor to an area-selecting crosshairs, ready for taking a (partial) screenshot.

Basty

message edited by Sebastian42


Report •

#10
September 16, 2016 at 21:37:02
ok, my bad! As far as I know, there's no way to substitute keyboard with mouse-clicks unless the application supports it as an alternative. If there's a way, greenshot may be able to help (or add it as a feature), or if there's a greenshot forum. good luck!
ps: you might look at "disability options" for windows, which allows substitution of key combinations at local environment level.

message edited by nbrane


Report •

#11
September 17, 2016 at 03:39:14
Re your #7

I have Autohotkey installed and files with the ahk extension call it up directly.

I put just my little bit of script at #6 into NotePad and saved it as test.ahk

I ran it and it put a snap of everything on the screen into the clipboard (I
copied into Paint to view it).

Always pop back and let us know the outcome - thanks


Report •

#12
September 17, 2016 at 04:52:09
If it works for you WITHOUT Greenshot, then Greenshot must be the problem. I do not want a screen shot - I want what Greenshot provides : mouse cursor turned into crosshairs ready to select an area OF MY CHOOSING for copying to the clipboard.

On your advice, I did look for a Greenshot forum, and placed my inquiry there, with no response so far.

When you say you 'ran' test.ahk, what precisely did you do ? - Had you converted it to an EXE (that would seem to be ideal) ?

For other purposes, I have an AHK launch with Windows, which may mean that Autohotkeys is always running.

Basty


Report •

#13
September 17, 2016 at 07:01:00
I just double clicked the file test.ahk to run it.

Just to clarify, you don't need Autohotkey program starting with Windows and always running in the background. During install the .ahk file extension will have been associated with Autohotkey, hence files of that type should start the program when double clicked. If that doesn't happen you can set the association in the normal way, such as right click .ahk file, select "Open With" then find the Autohotkey program.

AHK files (scripts) can be converted to EXE files so that they will run on any computer without needing the AHK program onboard. You right click the AHK file (when you've tested it thoroughly) then select Compile Script. OK for short scripts, results might be a bit inefficient for long ones.

Always pop back and let us know the outcome - thanks


Report •

#14
September 17, 2016 at 07:24:48
Reply to nbane;s footnote - 'you might look at "disability options" for windows' I SHOULD do that, but I fear it might be a 'global' solution, interfering with normal functioning in other 'situations' not connected with converting hotkey to mouse click.

Basty


Report •

#15
January 18, 2017 at 06:35:34
save as an .vbs file and run it:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^{PRTSC}"


Report •

#16
January 18, 2017 at 06:52:47
✔ Best Answer
It is now long ago that I found a PERFECT solution in using a quite simple script in Macro Express. SOLVED.

Basty


Report •

Ask Question