Ctrl-C doesn't copy to clipboard - SOLVED!

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Ctrl-C doesn't copy to clipboard - SOLVED!

Post by mightycpa » Thu Oct 16, 2014 5:58 am

I'm copying from a Firefox textbox. Sending the Ctrl-C doesn't work for MS, but it does work manually.

The script does highlight the text, but it does not copy the text to the clipboard.

Any ideas?

Code: Select all

Label>CheckImpossible
Remark>//if fret positions are all x's then don't bother
MouseMove>x_impossiblevar,y_impossiblevar
Wait>1
LClick>
Press LShift
Press Home
Release LShift
Wait>1
Press Ctrl
Send>C
Release Ctrl
Wait>1
GetClipBoard>fretText,0
Wait>1
MessageModal>fretText
Last edited by mightycpa on Sat Oct 18, 2014 6:41 pm, edited 1 time in total.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

UncleBen
Newbie
Posts: 6
Joined: Thu Oct 02, 2014 12:22 pm

Re: Ctrl-C doesn't copy to clipboard

Post by UncleBen » Thu Oct 16, 2014 8:52 am

Add a little wait between press ctrl and send>c :)

if it still not working, then try to delete the 0 parameter. I mean GetClipBoard>fretText.

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Ctrl-C doesn't copy to clipboard

Post by mightycpa » Thu Oct 16, 2014 1:15 pm

Thanks.

I went with some wait time between Press and Send and also Send and Release, and then I eliminated the optional parameter too.

So far, that seems to have done the trick. However,it is early in the testing phase.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Ctrl-C doesn't copy to clipboard

Post by mightycpa » Thu Oct 16, 2014 1:20 pm

Yeah, it just failed again. Not that doing this should matter, but is there any way to clear the clipboard before I copy? Then to check if it has contents?
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Ctrl-C doesn't copy to clipboard

Post by JRL » Fri Oct 17, 2014 4:44 am

What I sometimes do is set the clipboard to a known string then keep checking until it is something else.

Code: Select all

PutClipBoard>BLANK

Label>Loop
Press CTRL
Send>c
Release CTRL
Wait>0.2
GetClipBoard>vData
If>vData=BLANK
  Goto>Loop
EndIf

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Ctrl-C doesn't copy to clipboard. But Ctrl-c will.

Post by mightycpa » Sat Oct 18, 2014 12:45 am

Thanks JRL, that's a pretty good suggestion. But actually, I've identified the problem, and I will describe it fully for you, so that I can understand and remember.

First, a little bit of code:

Code: Select all

Remark>//release all the shifts
Release Shift
Release RShift
Release LShift

MouseMove>-69,-268
Wait>1
Let>SK_DELAY=10
LClick>
Wait>1
Press Ctrl
Wait>1.5
Send>A
Wait>1.5
Send>C
Wait>1
Release Ctrl
GetClipBoard>StrText
Wait>1
MessageModal>StrText
This code will issue a Ctrl-Shift-A, and a Ctrl-Shift-C.

I found this little utility called OSD Hotkey. http://www.romeosa.com/osdHotkey/help.html It records whatever your keyboard is doing, and it displays it in a persistent window.

I'm running this little test script on a Firefox page. It just happens that Firefox has a hotkey sequence, Ctrl-Shift-A, that opens its Add-ons Manager window. That's the only way I found this, because that Add-ons page kept opening up.

It turns out that when MS sees this:

Code: Select all

Send>A
it doesn't send "A". It actually sends Shift-lowercase-a. THAT is what is screwing me up.

Not CTRL-A, CTRL-C. It is sending CTRL-SHIFT-lowercase a, CTRL-SHIFT lowercase c

And Ctrl-Shift-a opens the Add-ons window.

So the correction to the code above is:

Code: Select all

LClick>
Wait>1
Press Ctrl
Wait>1.5
Send>a
Wait>1.5
Send>c
Wait>1
and it will work just fine. How about that?

Marcus, you should put that in the help somewhere. I banged my head on this problem for almost 4 days.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Ctrl-C doesn't copy to clipboard

Post by mightycpa » Sat Oct 18, 2014 5:02 am

While my little test script works reliably, my actual script doesn't work so well. I'm not sure what is going on with it, because I have no way to monitor the clipboard. All of the steps seem to work ok, but not the final result.

I've created an OCR scheme that seems to work in a little test script.

Code: Select all

Wait>1
SetFocus>Generator 6 - Mozilla Firefox: IBM Edition


Let>bmpfile=%script_dir%\gootar.bmp
Let>ocrfile=%script_dir%\gootar
Let>txtfile=%script_dir%\gootar.txt

MouseMove>0,-700
Wait>1
LClick>

Press Ctrl
Send>+
Send>+

Wait>1
ScreenCapture>530,-466,810,-430,%bmpfile%
Wait>1
Run>e:\tesseract-ocr\tesseract.exe "%bmpfile%" "%ocrfile%"
Wait>1
ReadFile>txtfile,result1



ScreenCapture>80,-254,486,-222,%bmpfile%
Wait>1
Run>e:\tesseract-ocr\tesseract.exe "%bmpfile%" "%ocrfile%"
Wait>1
ReadFile>txtfile,result2

Wait>1
Send>-
Wait>0.5
Send>-
Wait>1
Release Ctrl

messagemodal>%result1% and %result2%
Tomorrow, we'll see how it works in the real world.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

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

Re: Ctrl-C doesn't copy to clipboard

Post by Marcus Tettmar » Sat Oct 18, 2014 7:58 am

BTW I would use:

Press CTRL
Send>c
Release CTRL

Note LOWERCASE "c". Uppercase, as you have, can cause some apps to think you are sending SHIFT-C. So you end up with CTRL+SHIFT+C.

Always use lowercase when sending shortcut key sequences like this. You are sending the key sequence not characters.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Ctrl-C doesn't copy to clipboard

Post by mightycpa » Sat Oct 18, 2014 1:17 pm

Thanks. While this works perfectly fine in the abbreviated test script, it doesn't work in my main script. I've pored over that code to see if there is something that causes it, but I can't find it.

Here's the latest test script:

Code: Select all

Label>CheckImpossible
//mt_clip is a batch file with one line: echo off | clip
//it empties the clipboard
//but I can't run it in Windows 7 64bit
//Run>mt_clip
Wait>2
Remark>//if fret positions are all x's then don't bother
MouseMove>x_impossiblevar,y_impossiblevar
LClick>
Wait>1
Press Ctrl
Send>a
Release Ctrl
Wait>1
Press Ctrl
Send>c
Release Ctrl
Wait>1
GetClipBoard>fretText
Wait>1
MessageModal>fretText
Hash>%fretText%,MD5,strHash
If>strHash=2963a6d048379de68b68dc5abf498db6,Breakout,GetChordDescription

Label>GetChordDescription
MouseMove>x_chorddescvar,y_chorddescvar
LClick>
Wait>1
Let>SK_DELAY=10
LClick>
LClick>
Wait>1
Press Ctrl
Send>a
Release Ctrl
Wait>1
Press Ctrl
Send>c
Release Ctrl
Wait>1
GetClipBoard>StrText
Wait>1
MessageModal>StrText
Last edited by mightycpa on Sat Oct 18, 2014 6:40 pm, edited 2 times in total.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Ctrl-C doesn't copy to clipboard

Post by mightycpa » Sat Oct 18, 2014 6:38 pm

I found the problem in my application code that does not exist in the test code:

Code: Select all

// Variable Declaration

// Looping variables, for notes chords and frets
Let>n=0
Let>c=1
Let>f=0
As a result, later on:

Code: Select all

Release Ctrl
Press Ctrl
Wait>3
Send>c
MessageModal>Ctrl-c issued
Release Ctrl
sends a Ctrl-1, not a Ctrl-c. Because up above, c=1

The tool I mentioned earlier, OSDHotkey, was invaluable in this diagnosis.

This fixes the problem:

Code: Select all

// Variable Declaration

// Looping variables, for notes chords and frets
Let>nu=0
Let>ch=1
Let>fr=0
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

fthomas
Pro Scripter
Posts: 91
Joined: Fri Oct 03, 2008 6:40 pm

Re: Ctrl-C doesn't copy to clipboard - SOLVED!

Post by fthomas » Sat Oct 18, 2014 6:46 pm

Thanks for sharing your troubleshooting process. I've learnt a few things from it. I was actually struggling with one application. Kept doing odd things and I can only attribute it to the application. Windows will do weird things, so automation has become a bit more harder then ever.

Again, thanks for sharing!

Frank

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

Re: Ctrl-C doesn't copy to clipboard - SOLVED!

Post by Marcus Tettmar » Sat Oct 18, 2014 9:27 pm

Lesson learned: Use sensible variable names, and/or specify literal text.

E.g.

Let>varCounter=1

Send>{"c"}
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Ctrl-C doesn't copy to clipboard - SOLVED!

Post by JRL » Mon Oct 20, 2014 4:00 am

One more example why one should not use single character variables.

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