Send key combination to a window title

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Send key combination to a window title

#1 Post by MKANET » 11 Apr 2012 06:41

I am trying to figure any way possible (simplest is best) to send the following key combination to a Window Explorer window.

<CTRL> + <NUM+>

So... the batch file would emulate someone holding down the Control key and pressing the Plus sign in the numeric keypad at the same time.

Im pretty sure there isn't a native dos command. I am hoping someone here would have the expertise to still help. I tried VB Script "sendkeys"; however, it doesnt seem to know the difference between the two PLUS characters on an extended keyboard. At least, I couldn't figure it out. I found a somewhat free "SendKeys.exe" utility on the Internet; however, it looks like it might have some complications with licensing. I need my solution to be 100% worry-free from licensing since whatever I use is not for personal use.

Ultimately, my goal is to send this key combination to a Windows Explorer window; which will enable auto-column width. Unfortunately, this is the only way to enable this feature from command line that I know of.

Thanks in advance,
MKANET

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Send key combination to a window title

#2 Post by Squashman » 11 Apr 2012 06:49

Sounds like a job for AutoHotKey
http://www.autohotkey.com/

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Send key combination to a window title

#3 Post by Squashman » 11 Apr 2012 06:52

But it does look like you can use the + sign with Sendkeys. Did you put it in Curly Braces.
http://ss64.com/vb/sendkeys.html

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Send key combination to a window title

#4 Post by MKANET » 11 Apr 2012 06:53

Thanks. Ive tried that before (in reference to AutoHotKey). From what I remember, you actually have to have the application installed on whatever machine you need to run the compiled executable. At the most, I need very very tiny executable only. Not a full blown application that needs to be installed.

Also, VBscript CAN handle plus characters; however, I said, it can't tell the difference between either PLUS characters. There are two different ones on the keyboard. I specifically need the one on the numeric keypard.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Send key combination to a window title

#5 Post by Squashman » 11 Apr 2012 07:06

MKANET wrote:Thanks. Ive tried that before (in reference to AutoHotKey). From what I remember, you actually have to have the application installed on whatever machine you need to run the compiled executable. At the most, I need very very tiny executable only. Not a full blown application that needs to be installed.

Also, VBscript CAN handle plus characters; however, I said, it can't tell the difference between either PLUS characters. There are two different ones on the keyboard. I specifically need the one on the numeric keypard.


Not sure if this will work with VBscript or if it is just a .NET option.
{ADD}

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Send key combination to a window title

#6 Post by MKANET » 11 Apr 2012 07:11

Im actually hoping for a working example. I have already spent significant time trying to get it to work in VBScript. I'm really not that strong in VBScript.

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Send key combination to a window title

#7 Post by MKANET » 11 Apr 2012 09:05

For those that know VBScript, below is my code; which produces an "Invalid procedure call or argument Line4, Char1:

Code: Select all

Dim WshellObj   
set WshShell = WScript.CreateObject("WScript.Shell")   
WshShell.AppActivate "Logs"   
WshShell.SendKeys "^{ADD}"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Send key combination to a window title

#8 Post by foxidrive » 11 Apr 2012 12:54

MKANET wrote:I am trying to figure any way possible (simplest is best) to send the following key combination to a Window Explorer window.

<CTRL> + <NUM+>

Ultimately, my goal is to send this key combination to a Windows Explorer window; which will enable auto-column width. Unfortunately, this is the only way to enable this feature from command line that I know of.


Just a thought - I tried this in the GUI and it only works when a filename is in focus. If the directory tree was highlited it does nothing - is that going to be an issue?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Send key combination to a window title

#9 Post by aGerman » 11 Apr 2012 12:58

Sending key strokes is not possible using batch.
If you need to work with windows scripts you could use VBScript but this will not fully emulate the keyboard. Neither is each possible key implemented nor does it work for the common computer games (the game developers know such tricks). Also the SendKeys method does not distinguish between the letters block and the num block on your keyboard.
See
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

No warranty that you can apply that to your program.
*.vbs

Code: Select all

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Window title exactly as displayed on the task bar"
WScript.Sleep 500
WshShell.SendKeys "^{+}"
Set WshShell = Nothing

Regards
aGerman

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Send key combination to a window title

#10 Post by MKANET » 11 Apr 2012 13:57

Hi aGerman, actually the VBscript I posted earlier is the correct script (since I'm interested in the {ADD} character, not the {+}. Unfortunately, there's a bug with VBscript sendkeys that cant handle this keycombination.

I actually had to use AutoIt; which has a much better send command.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Send key combination to a window title

#11 Post by aGerman » 11 Apr 2012 14:03

That's not a bug, it's simply not supported as I already told you and as you can read at the first link.

Regards
aGerman

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Send key combination to a window title

#12 Post by MKANET » 11 Apr 2012 15:15

Sorry I didnt see that you already posted "SendKeys method does not distinguish between the letters block and the num block on your keyboard." I must have misread somewhere that {ADD} was for the numeric pad Plus; and, {+} is for standard.

Either way, the issue is moot since I already have a working solution using AutoIt. I appreciate the help though.

Post Reply