Page 1 of 1

Send key combination to a window title

Posted: 11 Apr 2012 06:41
by MKANET
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

Re: Send key combination to a window title

Posted: 11 Apr 2012 06:49
by Squashman
Sounds like a job for AutoHotKey
http://www.autohotkey.com/

Re: Send key combination to a window title

Posted: 11 Apr 2012 06:52
by Squashman
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

Re: Send key combination to a window title

Posted: 11 Apr 2012 06:53
by MKANET
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.

Re: Send key combination to a window title

Posted: 11 Apr 2012 07:06
by Squashman
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}

Re: Send key combination to a window title

Posted: 11 Apr 2012 07:11
by MKANET
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.

Re: Send key combination to a window title

Posted: 11 Apr 2012 09:05
by MKANET
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}"

Re: Send key combination to a window title

Posted: 11 Apr 2012 12:54
by foxidrive
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?

Re: Send key combination to a window title

Posted: 11 Apr 2012 12:58
by aGerman
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

Re: Send key combination to a window title

Posted: 11 Apr 2012 13:57
by MKANET
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.

Re: Send key combination to a window title

Posted: 11 Apr 2012 14:03
by aGerman
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

Re: Send key combination to a window title

Posted: 11 Apr 2012 15:15
by MKANET
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.