PDA

View Full Version : Script needed to emulate keystroke / mouse click in windows / terminal server



Shogan
06-04-2009, 04:07 AM
hi guys,

I'm looking for any kind of script that can emulate a keystroke / mouseclick in a terminal server session (Or even on the host PC it runs on with the Terminal server session in the foreground as the keystroke / mouseclick should then be done in this session.

Could anyone point me to a script or alternatively whip me some magical code to do this? It just needs to emulate a keypress or mouse click every thirty seconds.

Unfortunately I don't know very much about programming - all I can slightly remember is my high school Turbo Pascal teachings as well as some Visual Basic 5.0 from when I was in junior high school so I don't think I would be much good at doing this myself at moment. :/

Ideally it needs to run without needing to install any software other than perl... I have perl loaded so I can use that, or even a single compiled .exe would do the trick!

Any help muchly appreciated!

sabe
06-04-2009, 04:13 AM
Try auto it, very easy to use :)

XS_Rich
06-04-2009, 04:45 AM
Try auto it, very easy to use :)

+1

I use this A LOT at work

Shogan
06-04-2009, 05:19 AM
Try auto it, very easy to use :)

Hi thanks guys. Does auto it need to be installed to use? I need something that can run straight off - no installation required. Would auto it work like that? i.e. just an .exe that I can run that does the job without the need for installation / registry changes?

XS_Rich
06-04-2009, 06:10 AM
I've got it installed, but I think you can use it to compile scripts into executables.

Shogan
06-04-2009, 01:10 PM
I've got it installed, but I think you can use it to compile scripts into executables.

This seems to be the best solution so far as I found some code that does the trick and was then able to compile to a tiny .exe which doesn't require any special libraries etc.

At first the .exe was sending the keystrokes in a straight loop causing 50% CPU usage which would have made this impossible to use as it would slow the entire server down, but I found a delay command and used that to delay the loop 25 seconds each run. Now the CPU usage only jumps to 2% every 25seconds or so.

Thanks again!

Here is the Autoit code to send the kepresses "emulating" every 25 seconds for those interested:


; Press Esc to terminate script

Global $UnPaused
HotKeySet("1", "TogglePause")
HotKeySet("{ESC}", "Terminate")

While 1
Sleep(100)
ToolTip("Script is Paused",0,0)
WEnd

Func TogglePause()
$UnPaused = NOT $UnPaused
While $UnPaused
ToolTip("Sending...",0,0)
Send("emulating")
Sleep(25000)
WEnd
EndFunc

Func Terminate()
Exit 0
EndFunc

Works like a charm! :D

Shogan
06-05-2009, 08:27 AM
Hey guys,

So this works - but the problem now seems that whenever I minimise the Terminal Server session down with the script running, it doesn't work anymore even though the process is still running... So the idle timer kicks in again.. any ideas how to keep the autoit .exe script that I compiled going when the TS is minimised?

ahmad
06-05-2009, 08:43 AM
I was writing a response, but I just realized what you are saying. No autoit cannot manipulate a window that is minimized. Autoit sees what you see, you don't see autoit can't see it. Either get yourself another monitor, or setup a computer dedicated to doing this..

Did I understand your dilemma correctly or do I need to go see a psychiatrist?

XS_Rich
06-05-2009, 08:48 AM
Can you not use a mouse jiggler program on the remote PC to keep the session active?

Shogan
06-05-2009, 10:41 AM
Thanks ahmad that at least answers my question!

Razzle, that might be an idea too - going to look into an app that can do that. But I just realised - I have a phantom keystroker USB from thinkgeek that does mouse movements / keystrokes! I can use that too! Going to give it a try :D