Welcome Guest.   Make a donation to an author on the site September 01, 2014, 01:39:37 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
View the new Member Awards and Badges page.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1] 2 Next   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Simple Commandline to send Keystrokes (WinSendKeys)  (Read 26213 times)
Split_e
Supporting Member
**
Posts: 6

View Profile Give some DonationCredits to this forum member
« on: January 23, 2011, 06:50:52 PM »

This is continued from http://www.donationcoder....rum/index.php?topic=25388

I'm looking to use Screen Captor to basically screen cap every page of a book; the book software navigates to the next page via the Right Arrow key or Page Up key. Screen Captor can do the whole process, but only if I give it a proper commandline to invoke. So that brings me here.

Just looking for a couple of lines of code that I can plug into Screen Captor (in post-capture commandline option) to hit one key (either right arrow or page up) once. Thanks a ton in advance!
« Last Edit: February 11, 2011, 07:20:08 AM by mouser » Logged
mouser
First Author
Administrator
*****
Posts: 33,294



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: January 23, 2011, 07:04:06 PM »

so just to refine your request,

what you are looking for is a commandline tool that can send arbitrary keys (like right arrow, pageup, etc.) to the last active window, or optionally to a window specified by title/class/applicationexefilename.
Logged
rjbull
Charter Member
***
Posts: 2,748

View Profile Give some DonationCredits to this forum member
« Reply #2 on: January 24, 2011, 10:22:58 AM »

Why does it have to be command line?  There's some reason you can't use a macro program like Macro Express or PowerPro?
Logged
mouser
First Author
Administrator
*****
Posts: 33,294



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: January 24, 2011, 01:19:04 PM »

it has to be a commandline utility because he's going to launch it from another program when it needs to be run.
Logged
rjbull
Charter Member
***
Posts: 2,748

View Profile Give some DonationCredits to this forum member
« Reply #4 on: January 24, 2011, 04:57:33 PM »

Looks like NirCmd might be able to do it.  At least, it has "sendkey" type commands, but it doesn't seem to specify a target program or window.

Also looks like AutoHotKey may be able to read text from a file and type it as keystrokes to a program, or, maybe you can use Windows Scripting Host.  However, most of the Google hits appear to refer to sending keystrokes to a command window, not getting them from it.
Logged
Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: January 24, 2011, 04:58:16 PM »

Ok, I've not searched the internet, but just wanted to write a little AutoIt3 script that does exactly that for you:

Latest release & download moved to separate thread

WinSendKeys [-t Timedelay] [-d] [-w] <WindowName> <Keystrokes to send>
It takes 3 options and as much parameters (keystrokes) as you would like:
- -w <WindowName> : A window name or expression, as detailed in this page
- -t <Timedelay> : A number of milliseconds to wait between each set of keystrokes to send
- -d : Debug mode, writes some info into WinSendKeys.log in the current directory
- <Keystrokes to send> : Any amount of keystrokes that will fit the commandline, using the syntax from this page
(Be sure to double up any ^ marker for Control as it has a special feature in cmd.exe, so ^^n becomes Ctrl-N)


The compiled/non-upx'd exe is attached (updated: 2011-01-26)
« Last Edit: April 23, 2011, 10:55:17 AM by Ath; Reason: Re-routed to separate thread » Logged

wraith808
Supporting Member
**
Posts: 6,222



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #6 on: January 24, 2011, 09:29:34 PM »

Ath, I think we're not upx'ing them anymore because they're more likely to show up AV-positive if they are, so you might want to re-upload non-upx'd version.

See notification here.
Logged

Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: January 25, 2011, 11:39:47 AM »

Ath, I think we're not upx'ing them anymore because they're more likely to show up AV-positive if they are, so you might want to re-upload non-upx'd version.

See notification here.
Oh, I missed/forgot that announcement, though I read a lot about upx'ed exe's being flagged by virusscanners embarassed
Fixed it. And that's the second reason I published the source (first being this free-for-all), so anybody not trusting external exe's can re-compile it in a trusted environment.
Logged

Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #8 on: January 25, 2011, 05:19:30 PM »

I updated the original script, to write to WinSendKeys.log when -d parameter is used, effectively re-enabling this option. The compiled attachment is ofcourse also updated.

Thanks a ton in advance!
This might have triggered me, even though I just yet read close enough to spot it Kiss

Now let's wait for the OP to comment on this.
« Last Edit: January 25, 2011, 05:23:21 PM by Ath » Logged

Split_e
Supporting Member
**
Posts: 6

View Profile Give some DonationCredits to this forum member
« Reply #9 on: January 26, 2011, 01:30:19 PM »

Thanks so much guys! I have been following this and the other thread, and I just spent some time tinkering with it. Unfortunately, I'm having some issues. I'm pretty new to this stuff (I'm an engineering major, so my programming background is just VB6 and C++, some javascript). Can you tell me where I'm going wrong with this?

My "Tool Properties" window fields are:
Title: WinSendKeys
Program: C:\Users\Tyler\Books\Software\Ripping books\WinSendKeys.exe
Working Dir: C:\Users\Tyler\Books\Software\Ripping books\
Parameters: (blank)

I've tried a million variations of the commanline, but to be honest, I'm basically guessing. Of the many:
WinSendKeys <50> <"Materials"> <"{RIGHT}">
WinSendKeys [-t 50] [-d] [-w] <"Materials"> <"{RIGHT}">
WinSendKeys [-t 50] [-d] [-w] "Materials" "{RIGHT}"

The window is "Materials Science and Engineering: An Introduction, 8th Edition - CourseSmart Bookshelf". I've tried using the full name and different lengths, different times, different keys... :/

Any help is so very much appreciated!
Logged
Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #10 on: January 27, 2011, 05:52:09 AM »

My "Tool Properties" window fields are:
Title: WinSendKeys
Program: C:\Users\Tyler\Books\Software\Ripping books\WinSendKeys.exe
Working Dir: C:\Users\Tyler\Books\Software\Ripping books\
Parameters: (blank)
That looks alright to me, now add the below stuff into 'Parameters:'

WinSendKeys <50> <"Materials"> <"{RIGHT}">
WinSendKeys [-t 50] [-d] [-w] <"Materials"> <"{RIGHT}">
WinSendKeys [-t 50] [-d] [-w] "Materials" "{RIGHT}"

The window is "Materials Science and Engineering: An Introduction, 8th Edition - CourseSmart Bookshelf". I've tried using the full name and different lengths, different times, different keys... :/
Hm, I've used the default documentation conventions for including optional parameters in square-brackets '[]' and 'explaining words' in angle-brackets '<>', and those shouldn't be actually included in the parameter list.
If you need to use a title with multiple words separated by spaces, then surround that with double-quotes.

So your parameters could be:
[copy or print]
"- CourseSmart Bookshelf" {RIGHT}
To select the application CourseSmart Bookshelf with an opened document (the dash before CourseSmart indicates that), and send it a 'cursor right' keystroke, just like you pressed that key on the keyboard. If you want the PgDn key pressed, replace {RIGHT} with {PGDN}. You obviously found the list I referred. Wink
The timedelay should only be changed if your application can't handle the current speed of sending multiple keystrokes. It's only applied if the keystroke names/mnemonics are separated by spaces, so:
[copy or print]
"{RIGHT} {RIGHT}" : Sends Right-Cursor, Space, Right-Cursor without any delay
{RIGHT} {RIGHT} : Sends Right-Cursor, (delay for 100 msec), Right-Cursor
You can (and probably should) experiment/test from a cmd-prompt.
Logged

Split_e
Supporting Member
**
Posts: 6

View Profile Give some DonationCredits to this forum member
« Reply #11 on: January 27, 2011, 01:21:42 PM »

Awesome! Got it to work. Your explanation was very helpful Ath, but in the end, I needed to figure out what to put in:
"Post Capture Commandline Tools to Run - Invoke these command lines after each capture" Box on Screenshot Captor. I mistakenly thought that those commandlines called the Tools in the way they were configured with screen captor. Once I added the parameters to that line of code, everything worked great.

Unfortunately, the software I was using was updated yesterday to my dissapointment and they removed all keyboard shortcuts for changing the page. So I used AutoHotKey to send a mouse click to the particular button every time certain keystrokes were sent, then I used your tool to send those keys. Everything is working great! Thanks so much!

You've all been a huge help, with the quick replies and scripting. Thanks again!

Edit: I'm going to wait until I get paid so I can put in a bigger donation.
« Last Edit: January 28, 2011, 11:17:09 AM by Split_e » Logged
Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #12 on: January 28, 2011, 02:08:50 PM »

I've been fiddling with the script last night, and now it can also send mouse-clicks (so you won't need the separate ahk script for that). I'd call it v2.0 I guess undecided

I'll write down a readme, do some more testing, and wrap it all in one zip file for a little easier download, later tonight.
Logged

rjbull
Charter Member
***
Posts: 2,748

View Profile Give some DonationCredits to this forum member
« Reply #13 on: January 28, 2011, 02:47:34 PM »

I'll write down a readme, do some more testing, and wrap it all in one zip file
Thmbsup
Logged
Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #14 on: January 28, 2011, 04:54:06 PM »

So, got the most stuff tested and corrected, and a readable readme done, so I can release WinSendKeys 2.0

Latest release & download moved to separate thread

Here's the Changelog for 2.0, copied from the script:
; 2011-01-27, version 2.0-beta,
; + Added mouse-modes, postfix with ## for ControlClick, #% for MouseClick
; + Added more logging and messages
; 2011-01-28, version 2.0,
; * Changed WinTitleMatchMode to be case-insensitive
; ! Fixed MouseClick mode
; + Allow Activate-Only by giving no keystrokes
; - Window not found message shows only in debug mode
; - Updated helpmessage

Hm, maybe Mouser could move/split this thread to the Coding Snacks/Finished section, as that's what it basically was  embarassed

Attachment includes AutoIt3 source, readme and .exe
« Last Edit: April 23, 2011, 10:56:20 AM by Ath; Reason: Re-routed to separate thread » Logged

Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #15 on: January 30, 2011, 09:09:50 AM »

Another update and now WinSendKeys 2.5 is released

Latest release & download moved to separate thread

The changelog for 2.5 since the previous release, copied from the script:
; 2011-01-29, version 2.5-beta
; + Added -f strokesfile option to read keystrokes and mousestrokes from named file,
;            commandline strokes are handled first
; - Minor adjustments
; 2011-01-30, version 2.5
; ! Avoid ever overwriting the script with debug-log-file (if not .au3 or .exe extension, add .log to scriptname)
; + Added reading settings from optional .ini file:
;   Get parameters from .ini file with the same name as this script/exe, only if the file exists, create file manually!
;   Sectionname: [Settings]
;   Variables:
;   delay=100 : delay between keystrokes/mousestrokes sent to the application
;   mousestrokes=0 : Enable mousestrokes by setting this to 1
;   mousespeed=0 : Speedfactor for mouse move, value between 0 and 100, 0 = immediate, 1 = fast, 100 = slow
; - Documented and optimized script functions

Attachment includes AutoIt3 source, updated readme, a sample strokefile (.stro) and .exe
« Last Edit: April 23, 2011, 10:56:51 AM by Ath; Reason: Re-routed to separate thread » Logged

asihuay
Participant
*
Posts: 2

View Profile Give some DonationCredits to this forum member
« Reply #16 on: February 01, 2011, 06:44:03 PM »

Hi to all.
I need example of full command line to send keystrokes to an excel vba userform1
I am trying  the following:
UserForm1.Show vbModeless
Shell "S:\WinSendKeys.exe -w:UserForm1 Tab"   'try to send   Tab key to UserForm1
Shell "S:\WinSendKeys.exe -w:UserForm1 a"   'try to send   "a"   to UserForm1
thanks in advance.
Logged
Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #17 on: February 02, 2011, 01:35:59 AM »

Please re-read the readme file, it has samples and explanations, and weblinks to the key mnemonics to use.

Your sample could look something like this, assuming the title of your form really is 'UserForm1' :
[copy or print]
Shell "S:\WinSendKeys.exe -w UserForm1 {TAB} a"   'try to send Tab key &&  "a"  to UserForm1

But eventually, Excel vba offers enough methods to control that dialog directly, you don't need an external tool for that.
Probably someone with more vba experience can help out here?
Logged

asihuay
Participant
*
Posts: 2

View Profile Give some DonationCredits to this forum member
« Reply #18 on: February 02, 2011, 02:46:08 PM »

Thanks for the code.
Yes for control userform with vba is very easy I use it only to example in order to obtain the correct command line code.
My need are to open in default browser all network camera in sequence all are protected by user and password at this point I will use winsendkeys and then run snapshot(alt+S) then enter to take picture.
At this time I successfully obtain the required snapshot.
Thanks.
Logged
Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #19 on: February 07, 2011, 04:21:31 PM »

Another update and now WinSendKeys 2.6 is released.

Latest release & download moved to separate thread

The changelog for 2.6 since the previous 2.5 release:
; 2011-02-07, version 2.6
; + Added -c option to read keystrokes from the clipboard, as requested by mouser & kikon in this thread: http://www.donationcoder....rum/index.php?topic=25553
; + Added -cn option, like -c, but does not send an {ENTER} after each line, can be added after -c or -cc to disable the {Enter} being sent
; + Added -cc option, like -c but embeds the clipboard into the KeyStrokes commandline sequence using #$ prefix, see readme for details

Attachment includes AutoIt3 source, updated readme, a sample strokefile (.stro) and .exe

(Edit: typo fixed)
« Last Edit: April 23, 2011, 10:57:25 AM by Ath; Reason: Re-routed to separate thread » Logged

kikon
Participant
*
Posts: 19

View Profile Give some DonationCredits to this forum member
« Reply #20 on: February 08, 2011, 04:14:46 PM »

thanks a lot Ath !
I used this line :
WinSendKeys -w "Help and Support Center" -c

but what to do when application is not running. In most cases, we should send clipboard content to app that not running at the moment...

to use cmd.exe ? or you can add this feature to your utility ?
« Last Edit: February 08, 2011, 04:28:33 PM by kikon » Logged
Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #21 on: February 08, 2011, 04:48:51 PM »

I thought about that when working on this extension, but could not make a decision whether to add that as a feature or not. It's quite a different feature, as the executable of the file to load usually doesn't have much relation with the title of an active window. It would most likely require an extra commandline parameter. And while that's not really bad, it's imho a bit off of the original idea.

I'll think about it for a bit, and write here what I decide.
Logged

Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #22 on: February 09, 2011, 01:40:49 PM »

I'll think about it for a bit, and write here what I decide.

Ok, I'll add a "-x" option, if it pleases you, that's fine (and fun) for me Cool
Logged

Ath
Supporting Member
**
Posts: 2,201



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #23 on: February 09, 2011, 05:58:04 PM »

Yet another update, and I've named it WinSendKeys 3.0 Kiss

Latest release & download moved to separate thread

The excerpt from the changelog since 2.6, included in the source:
; 2011-02-09, version 3.0
; + Added -x executable_filepath option to start if WindowName is not found or executable filename is not found running
; + Added -xp executable_parameters option to specify parameters to executable_filepath

As usual, I updated the readme, compiled the AutoIt3 source into an exe, and pushed it all together in a zipfile, attached to this post.
« Last Edit: April 23, 2011, 10:57:57 AM by Ath; Reason: Re-routed to separate thread » Logged

kikon
Participant
*
Posts: 19

View Profile Give some DonationCredits to this forum member
« Reply #24 on: February 10, 2011, 05:21:23 PM »

thank you Ath, but -x doesn't work yet. I used in various way, doesn't work Sad
d:\run\WinSendKeys\WinSendKeys.exe -x C:\WINDOWS\pchealth\helpctr\binaries\helpctr.exe -c

helpctr.exe just started and nothing is pasted.
« Last Edit: February 10, 2011, 05:38:55 PM by kikon » Logged
Pages: [1] 2 Next   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.166s | Server load: 0.12 ]