Cannot get CTRL+V to work 4 paste operation after compile

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
montanan
Junior Coder
Posts: 49
Joined: Mon Jul 09, 2007 3:44 pm
Location: San Jose, CA

Cannot get CTRL+V to work 4 paste operation after compile

Post by montanan » Thu Jan 08, 2009 7:04 am

I have developed a simple time and date "stamper" that works fine under Macro Scheduler.

However, after I compile it, the last section (which pastes the date into whatever app the user is working in) no longer works

Here's the code...

Code: Select all

IfDirExists>c:\stamper,continue
CreateDir>c:\stamper
WriteLn>c:\stamper\stamper.ini,resultvar,Initialization file for Stamper%CRLF%
Input>username,What is your user name?
EditIniFile>c:\stamper\stamper.ini,settings,user,%username%
MessageModal>Installation complete!
Label>continue
//Open c:\stamper directory
'ExecuteFile>c:\stamper
//
ReadIniFile>c:\stamper\stamper.ini,settings,user,username
Year>year
Month>month
Day>day
Hour>hour
Min>min
Let>stamp=%year%-%month%-%day% %hour%:%min%_%username%: 
PutClipBoard>stamp
'Let>MSG_STAYONTOP=1
'Message>Clipboard populated by Stamper!
WaitClipBoard
Wait>1
//when I compile this, the following section doesn't work
Press Ctrl
send>V
Release Ctrl
I would greatly appreciate any thoughts on how to make this work. I've tried very long wait times, etc., but nothing seems to work yet.

-Richard
[/code]

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

Post by JRL » Thu Jan 08, 2009 2:06 pm

Just a thought.
Try setting focus to the window you want to paste into. If the window doesn't have focus, it won't accept the clipboard data.

montanan
Junior Coder
Posts: 49
Joined: Mon Jul 09, 2007 3:44 pm
Location: San Jose, CA

SetFocus has not worked yet

Post by montanan » Thu Jan 08, 2009 2:31 pm

JRL,

Thanks for your input. I have tried a variety of SetFocus> approaches as well, but haven't been able to get it to work.

It's just a hunch, but I may need to find a way to tell MacroScheduler where the cursor is at the point when the macro is executed. I'm not sure exactly how to do that.

-Richard

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 Jan 08, 2009 3:40 pm

Where do you want the CTRL-V to happen? At present looks like the last focused window is the Explorer window. But I don't know where the cursor will be. Are you intending to send ctrl-v to the explorer window?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

montanan
Junior Coder
Posts: 49
Joined: Mon Jul 09, 2007 3:44 pm
Location: San Jose, CA

Post by montanan » Thu Jan 08, 2009 4:21 pm

The user will be in a tab in Firefox which has a title above called...

SugarCRM - Mozilla Firefox

... and the cursor will be in a text area, awaiting input.

Thank you.

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 Jan 08, 2009 4:23 pm

But your script is not focusing anything. When you start the EXE focus will change (it will get the focus). So you need a SetFocus line. You need to focus SugarCRM.
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
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Jan 08, 2009 6:45 pm

Hi montanan,

The easiest way to use the script you've written is uncompiled... on a machine with Macro Scheduler installed... just assign it a Hot Key and when you're in that SugarCRM field, tap the Hot Key - sounds like that's working OK for you.

Since you are trying to get it to work compiled, I assume you want to have other users (that don't have Macro Scheduler on their machines) use it. If so, how are you triggering the macro on those other machines? Without Macro Scheduler installed, you can't just set a Hot Key.

One way is to create a desktop shortcut icon, point it to the compiled exe on their PC and set a Hot Key in the properties of that icon... just make sure you use some Hot Key combination that no other application is likely to use or you may have problems.

When the user hits that Hot Key and your exe starts up, yes... focus will move from your SugarCRM window to your exe and so your problem becomes, how do you get focus back to where you want it so that when it pastes, the text will go there?

Question - is this macro you wrote *only* to be used for SugarCRM? If so, then yes, you could add a SetFocus line to set the focus back on SugarCRM.

However, if your macro is meant to be a general purpose date stamper to stamp into a variety of apps, then that won't work well... but here's an alternative. Have your macro send ALT TAB just before it sends the date text. That will tell Windows to "switch focus back" to the app that previously had focus... before your exe took focus. That way you will be able to use it to stamp into notepad, Word, SugarCRM, etc.

Be sure to use some Wait> statements in between the keys you're sending to give windows time to react. You can start at a second or two and then keep paring it down to make it faster... while testing to make sure its still reliable on the machines you are running on.

Let us know how you make out...

By the way, if you are willing to have your exe running all the time on the target machine... watching for a particular combination of keys to be pressed, you could also check out the OnEvent> command in the Help File... specifically KeyDown, i.e.:
Help File wrote:OnEvent>KEY_DOWN,VK32,3,KeyPress
The above line waits for ALT+Space to be pressed and when it is, it sends execution to the "Keypress" subroutine... you could have most of your code in there to accomplish your datestamp... again see the example Marcus has for OnEvent> in the Help File.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

montanan
Junior Coder
Posts: 49
Joined: Mon Jul 09, 2007 3:44 pm
Location: San Jose, CA

Post by montanan » Fri Jan 09, 2009 1:03 am

jpuziano,

THANK YOU!

Your Alt-Tab suggestion did the trick, at least for XP (a few users on on Vista and it seems that Microsoft changed the way Alt-Tab works because Alt-Tab now goes to the "next" window not the "original" window in Vista).

I actually started with a more general purpose (preferred) idea and then paired it down to only SugarCRM using...

WindowAction>1,SugarCRM*
SetFocus>SugarCRM*

... because I hadn't tried your Alt-Tab idea.

With your suggestion, it worked with the following code (for XP so far, I'm still working on Vista)

Code: Select all

IfDirExists>c:\stamper,continue
CreateDir>c:\stamper
WriteLn>c:\stamper\stamper.ini,resultvar,Initialization file for Stamper%CRLF%
Input>username,What is your SugarCRM user name?
EditIniFile>c:\stamper\stamper.ini,settings,user,%username%
MessageModal>Installation complete!
Label>continue
ReadIniFile>c:\stamper\stamper.ini,settings,user,username
Year>year
Month>month
Day>day
Hour>hour
Min>min
Let>stamp=%year%-%month%-%day% %hour%:%min%_%username%: 
Wait>1
Press Alt
Press Tab
Release Alt
Send>%stamp%
PutClipBoard>stamp
-Richard

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Jan 09, 2009 5:02 am

Hi montanan,

Well I'm glad that worked for you... but I was wondering why the last line in your code was:

PutClipBoard>stamp

Up until that last line, you hadn't changed the clipboard contents... and you didn't need to use the clipboard to get the stamping done. My guess is you want it in there so they can... hit CTRL V to paste it again... later perhaps? If you are triggering your exe macro via a Hot Key (perhaps set on a desktop shortcut icon)... why not just get them to tap the Hot Key again? It will work just the same a second time around, perhaps better as the time will be fresher.

The reason I mention this is... what if the user had some text in their clipboard they were going to paste somewhere... but they decided to hit the Hot Key for your datestamper first. Oops, their text on the clipboard has now been lost, overwritten by your macro.

To prevent situations like this, when I write a macro that changes data on the clipboard, I always save what they already have in there first... then restore it when my macro is done using the clipboard, something like this:

Code: Select all

GetClipBoard>original_clipboard_contents

//lines that change clipboard data go here...

PutClipBoard>original_clipboard_contents
The above is fine for preserving text in their clipboard... but if they had image data in there, it would be lost. Its even possible to prevent that though... check the following posts if interested:

Detect Image Data on Windows Clipboard plus Save and Restore
http://www.mjtnet.com/forum/viewtopic.php?t=2622

Clipboard Image Save-To-File and Restore-From-File (enhancement request)
http://www.mjtnet.com/forum/viewtopic.php?t=2658

Take care and thanks for sharing your date stamper code.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

montanan
Junior Coder
Posts: 49
Joined: Mon Jul 09, 2007 3:44 pm
Location: San Jose, CA

Post by montanan » Fri Jan 09, 2009 6:01 am

Thanks, jpuziano.

Good input on the clipboard. I think it's better to leave it out altogether, in order to make sure the date & time are always current.

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