Using AHK with a VM or without a keyboard attached Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TechGirlMN
Posts: 5
Joined: 18 May 2017, 15:48

Using AHK with a VM or without a keyboard attached

18 May 2017, 16:10

Here's the issue I having with a VM, When I'm remoted in the scripts that I'm trying to run work great. But, when end the remote session and then try to run the same scripts they don't work, no keystrokes are being sent. For example:

Code: Select all

IfWinExist, Untitled - Notepad
	WinActivate, Untitled - Notepad
Send, The quick brown fox jumped over the lazy dog.
MsgBox, 4, , yes the script ran.
This example runs fine if I trigger it manually, or as an .exe. The text gets added to the notepad file and the Message Box appears.

If I end my remote session and have task scheduler run the .exe for me, I come back to Notepad being active but blank, and the Message Box appears as well.
I've tried changing the Send to Input and SendInput, with the same result.

Suggestions?
:headwall: :headwall: :headwall: :headwall: :headwall: :headwall: :headwall: :headwall: :headwall:
TechGirlMN
Posts: 5
Joined: 18 May 2017, 15:48

Re: Using AHK with a VM or without a keyboard attached

19 May 2017, 09:05

I followed these instructions, and no luck. the .bat file doesn't log me off. and it's not that the scripts don't run, it's that none of my keystrokes get sent.
in this updated example

Code: Select all

IfWinNotExist, Untitled - Notepad
	Run, Notepad


IfWinExist, Untitled - Notepad
	WinActivate, Untitled - Notepad
Send, the quick brown fox jumped over the lazy dog. 
MsgBox, 4, , yes the script ran.
if I have it run through task scheduler and close the remote desktop, Notepad opens, and I get the Message Box but Notepad is blank. same as the script that I'm really trying to run which doesn't go past the login screen, because the password is never entered.


Code: Select all

Run, C:\Users\Public\Desktop\Horizon 7.5.4.lnk
     
;Run, C:\Program Files (x86)\SirsiDynix\Horizon\Launcher.exe ; got errors when 
;using 'real' path

Sleep, 20000
Send, [redacted}
Sleep, 250 
Send, {enter}
Sleep, 10000
TechGirlMN
Posts: 5
Joined: 18 May 2017, 15:48

Re: Using AHK with a VM or without a keyboard attached

19 May 2017, 13:01

HotKeyIt wrote:Try running bat file as Admin!
Okay per your suggestion, I ran the logoff.bat as admin, yes it logged me out, but the results were the same. Notepad opened, no text was added, and the Message box was up. I even added a delays so notepad had time to open and a delay so that the message box popped after 5 seconds, So it's not the the script doesn't run, It runs, but any kind of string or key combo isn't being passed/entered. here's a Google doc with screenshots https://docs.google.com/document/d/11dD ... sp=sharing
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Using AHK with a VM or without a keyboard attached

19 May 2017, 13:04

Ok, now try this:

Code: Select all

IfWinNotExist, Untitled - Notepad
{
  Run, Notepad,,,PID
  WinWaitActive, Untitled - Notepad ahk_pid %PID%
} else
  WinActivate, Untitled - Notepad
Send, the quick brown fox jumped over the lazy dog. 
MsgBox, 4, , yes the script ran.
TechGirlMN
Posts: 5
Joined: 18 May 2017, 15:48

Re: Using AHK with a VM or without a keyboard attached

19 May 2017, 14:21

Okay that was weird, I created a new .exe with your code. Ran just fine logged in, because of course it did. Set up the exe to run via Task Scheduler and logged off using the .bat and waited. logged back in, notepad was up, but blank. when i clicked on the title bar the script finished. "ick brown fox jumped over the lazy dog." ended up in notepad, and then the message box popped. Tried it again to see if logged in too soon, and got a similar result, the text did not appear until I clicked on the window for notepad. although since I clicked on the main part of the window and not the title bar I got the whole line of text.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Using AHK with a VM or without a keyboard attached  Topic is solved

19 May 2017, 15:42

try

Code: Select all

IfWinNotExist, Untitled - Notepad
{
  Run, Notepad,,,PID
  WinWait, Untitled - Notepad ahk_pid %PID%
  WinActivate
  WinWaitActive
} else
  WinActivate, Untitled - Notepad
Send, the quick brown fox jumped over the lazy dog. 
MsgBox, 4, , yes the script ran.
TechGirlMN
Posts: 5
Joined: 18 May 2017, 15:48

Re: Using AHK with a VM or without a keyboard attached

22 May 2017, 09:40

:dance: :bravo:
Yes, that worked. I got both the test script and my 'real' script to work. Thank you so much!!!!
:beer: :superhappy:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Holarctic, Rohwedder and 203 guests