Copying Data To Clipboard

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Copying Data To Clipboard

Post by PaulSR » Tue Feb 11, 2014 1:52 pm

Hi,

I was wondering if anybody knows of a way to copy data to the clipboard without using mouse or keystrokes? I'm having problems with a script where the keypresses don't work on the run after building an executable then are fine after so I'd like to find a workaround.

Thanks in advance.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 11, 2014 2:29 pm

The only way to do it without using mouse/keyboard would be to send a WM_COPY message directly to the control.

http://msdn.microsoft.com/en-us/library ... s.85).aspx

To do this you need:

1. To grab the handle of the control (so it needs to be a windowed control that has a handle). If it is a "grabbable" control you can use FindObject to get a handle to it.

2. Use LibFunc and the SendMessageA API to send the WM_COPY

3. You'd first need to find a way to SELECT the text or nothing is going to get copied.

Frankly I'd be inclined to find out why your keypresses don't work than try fixing that with the above. Keypresses should work.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Post by PaulSR » Tue Feb 11, 2014 2:47 pm

No dice for me on that front - it's a citrix receiver window. Have tried as many combinations as I can think of when trying to figure out why it doesn't like the keystrokes but can't fathom it. Like I said it works after the first attempt and even after a reboot of the pc but the very first time an executable is run the keystrokes don't work. There are other instances of keystroke presses in the code including the same LCTRL+a / LCTRL+c combination which work and I've tried changing the wait between keys to anwhere from 0.1 to 0.5. It's very strange.

Thanks for the info!

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Post by PaulSR » Tue Feb 18, 2014 11:31 am

Hi,

Further to your advice Marcus we've been plugging at this and we've narrowed it down to a single point of failure.

If the application into which the keystrokes are sent is minimised before the script is run then it fails to send the below keys to the window and no data is collected whereas if the application is onscreen (even hidden behind another window) it will function as expected. This is the code it's very straightforward :

Code: Select all

WaitClipBoard

SetFocus>WindowHandle
CapsOff
Press LCTRL
Wait>0.5
Send>c
Wait>0.5
Release LCTRL

Wait>0.3

GetClipBoard>DiaryData
So like I say as long as the application referenced by WindowHandle is onscreen this will work but if it's minimised before the script begins (there's a lot of script before this bit) then it will fail.

Does anybody have any idea why that might be the case?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Feb 20, 2014 5:09 pm

Citrix can be a pain sometimes. We have found that you sometimes need to legacy mode with Citrix when sending keystrokes:

Let>SK_LEGACY=1
Send>whatever

Let me know if that helps.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts