Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Send KeyStroke to CMD



  • Please log in to reply
32 replies to this topic
Hondo
  • Members
  • 17 posts
  • Last active: Aug 26 2014 11:50 AM
  • Joined: 25 Aug 2014

Hi Guys,

 

I just need a simple script send "num lock" keystroke to an already opened CMD.exe window which is unfocused while Im in game.

Can someone please help me with this.

 

I'm trying to figure it out my self and have been unable so far.

 

Thanks,

Hondo



floodindahood
  • Members
  • 383 posts
  • Last active: Apr 20 2018 01:45 PM
  • Joined: 21 Oct 2011

What you're looking for is "ControlSend" from http://www.autohotke...cs/commands.htm.



Hondo
  • Members
  • 17 posts
  • Last active: Aug 26 2014 11:50 AM
  • Joined: 25 Aug 2014

I have been looking at it.... but I just have no idea how to even start the script.



lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013

Hi Hondo,

 

Here is an example of a script I use:

  1. ! + ` runs this script
  2. Run the cmd with the command 'irb', seting the default directory and putting the pid of the cmd window in the variable 'this_console'
  3. Wait for the cmd window to be active
  4. Set the Key Delay so my ControlSend commands don't mess up
  5. Use ConstrolSend to send text directly to the cmd window using the pid stored in 'this_console'
; Opensruby interperter
#IfWinActive
!`:: ; Opensruby interperter, sends blahtext
Run, %ComSpec% /K "irb", %A_Desktop%\blah_folder1\blah_folder2,,this_console
WinWaitActive, ahk_pid %this_console%
SetKeyDelay, 0, 10
ControlSend,, {Shift up}{Alt up}, ahk_pid %this_console%
ControlSend,, require 'some_file_for_ruby1'{Enter}, ahk_pid %this_console%
ControlSend,, require 'some_file_for_ruby2'{Enter}, ahk_pid %this_console%
ControlSend,, include some_file_for_ruby1{Enter}, ahk_pid %this_console%
ControlSend,, include some_file_for_ruby2{Enter}, ahk_pid %this_console%
return

Note: In this case I use the run command to open the command prompt and get the command prompts pid in the variable 'this_console', every ControlSend I send I use that pid.

 

Run

WinWaitActive

SetKeyDelay

ControlSend


My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm


Hondo
  • Members
  • 17 posts
  • Last active: Aug 26 2014 11:50 AM
  • Joined: 25 Aug 2014

Thanks Lifeweaver,

 

But I'm still struggling with this. I have no idea how to get this to work.

 

I dont need the script to open up CMD as It will be already open. I just need to send the "Enter" key stroke to CMD prompt that is already open but minimised while i'm in game or another application.

 

Someone said to run Window Spy Utility and click on the CMD window to get the classNN. When I window Spy I get the the following for the CMD window and I dont see a classNN.

 

>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
C:\WINDOWS\system32\cmd.exe
ahk_class ConsoleWindowClass
 
>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 4644, 681  (less often used)
In Active Window: 3947, 535
 
>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
 
Color: 0xF0F0F0  (Blue=F0 Green=F0 Red=F0)
 
>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: 697     top: 146     width: 1017     height: 763
 
>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<
 
>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
 
>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<
 
>>>>( TitleMatchMode=slow Visible Text )<<<<
 
>>>>( TitleMatchMode=slow Hidden Text )<<<<
 
 
If someone can please help me with this It will be great. I dont need it to do anything fancy, just want it to send the "enter" keystroke to the CMD while it is minimised.
 
Thanks,
Hondo


Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013
ControlSend, , {enter}, cmd  ; Send directly to a command prompt window.


Hondo
  • Members
  • 17 posts
  • Last active: Aug 26 2014 11:50 AM
  • Joined: 25 Aug 2014

Hi Xtra,

 

Is that the full script I need to run with out editing it? I tried it and it didnt work. Did it would for you?

 

Thanks,

Hondo



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013

I used a hotkey to activate it and yes it worked while the console was minimized.

 

 

I rechecked everything it only works when running cmd.exe as admin.


Edited by Xtra, 26 August 2014 - 03:49 AM.


Hondo
  • Members
  • 17 posts
  • Last active: Aug 26 2014 11:50 AM
  • Joined: 25 Aug 2014

Sorry mate, bit of a newbie when it comes to this.

 

What you mean by hotkey?

 

Just pressing "enter" key is not enough? Do I need to set the hotkey some where?



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013
$Enter::ControlSend, , {enter}, cmd  ; Send directly to a command prompt window.

use that if you want a enter key hotkey
 Edit sry forgot $ prefix 

Edited by Xtra, 26 August 2014 - 03:59 AM.


Hondo
  • Members
  • 17 posts
  • Last active: Aug 26 2014 11:50 AM
  • Joined: 25 Aug 2014

Hey Mate,It doesn't seem to work for me... Not sure why.

 

This is what I have done so far.

 

- Created file called test.ahk

- Copied the script from above:

$Enter::ControlSend, , {enter}, cmd ; Send directly to a command prompt window.

-Saved it.

- Right click on the file and click on "Run Script"

- I can see the AutohotKey has started.

- I press the "Enter" key.

- Check my cmd window and nothing.

 

Is there anything else im missing.



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013

Are you running cmd.exe as admin?



Hondo
  • Members
  • 17 posts
  • Last active: Aug 26 2014 11:50 AM
  • Joined: 25 Aug 2014

No... should I be?



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013

Yes the only way i couldnt get it to work was to not run as admin.

When posted it originally i forgot my shortcut to cmd is allways run as admin.



Hondo
  • Members
  • 17 posts
  • Last active: Aug 26 2014 11:50 AM
  • Joined: 25 Aug 2014

hi Xtra,Im not running it as Admin. It just doesnt seem to want to work....