Wait on user keystrokes

crystal007

  • Joined: Sep 22, 2010
  • Posts: 2

Wed 9/22/2010 - 18:06

Hello everyone,

I have just started to explore Winautomation and it looks great so far. However, I'm puzzling around to figure out how I can create an action to make the makro wait on a specific user keystroke before it proceeds. Thats what I want to realise:

On first start of the makro it gets date and time and writes it to a file "memo.txt", after that it should wait until the user presses Ctrl + C (on copying text from any active window), write the clipboard content into memo.txt and goes back to the state to wait on user keystrokes Ctrl + C. So as long as the makro runs, every new clipboard content is appended to the already existing content in memo.txt. The purpose is a kind of hidden memo file that I don't have to switch to, paste and save manually every time, but just have to highlight, hit Ctrl+C and its appended to the memo file. (Based on the intermediary example 1, Paste to text file, but with the difference that it does not only run once and then stops, but stays on "standby" so to speak and does that every time again, when something new is copied to the clipboard).

Until date/time it works fine, but I couldn't find this command to wait on keystroke, although I would think that this is a very common and often repeated action that we do countless times a day and is one of the most important to automate. I tried "send keys" with Ctrl + C but don't see any "wait" command other than xx seconds (can't use that since of course I can't know beforehand, how many seconds elapse until the copy action will occur) or process etc. So it doesn't wait but jumps back and forth without pasting clipboard content. I have also tried to put the {Control}({C}) into a variable %hotkeyCopy% and use "If %hotkeyCopy% = true then Get Clipboard text , Write text to file. But doesn't work as well.

So basically I would like to have it do this:

If user hits Ctrl + C then get Clipboard text and write this text into memo.txt (and have it repeat this as long as the makro is running). Does anyone have an idea how I can do this?

Thank you in advance

Sabine

 

#1

Samantha

  • Joined: Apr 23, 2010
  • Posts: 2326

Fri 9/24/2010 - 13:25

Hello Sabine, Just a while ago I created a job such as. It runs on a keyboard trigger (Control+Shift+C), where you can append any piece of text to a text file. Please find the job attached. I used a different trigger to the one you want to use, so that I can still use the control+c to copy other bits and pieces without having it all appended to the text file. :) Samantha

append text to memo_1.waj

#2

crystal007

  • Joined: Sep 22, 2010
  • Posts: 2

Fri 9/24/2010 - 20:39

Hello Samantha,

 

Thank you so much for your help and your script.

I did make 3 versions already of my memo makro, but since I wanted to compile it, so it can be used from a USB stick for example, I didn't think on the option with the triggers. Though, actually, if as exe file it can also be started with a hotkey. I also wanted that the date is only written one time, in the first entry of the same day, as it gets quite inconvenient, if for example we paste different text pieces that belong together into the memo and later have to remove all the dates manually. So my first versions write the date/time into the memo, open a display which waits until you copy a text and click OK, then it appends the memo and reopens the display box. Works, but is not really convenient too with the box and always having to click okay.

Now your script is a very beautiful help and inspiration. I have modified it, so it is now writing the date and time the first time that day only, and every other copy/paste action is written without date and time. I have used my very first regular expression for this (by following the regular expression thread and getting Expresso) and am quite excited that it works :)

If you want and for anyone else who wants it, I attach the job below (called it "Memo Butler").

Thaks again

Sabine

MemoButler4.waj

#3

Samantha

  • Joined: Apr 23, 2010
  • Posts: 2326

Mon 9/27/2010 - 14:19

Hello Sabine, You could actually use a persistent variable to hold the date for which the job last run and append a new line to the text file in the event the date did not match the one stored. You can find persistent variables in the release candidate for WinAutomation 3.1. Regarding having to wait for the text to be copied, you could I suppose create a trigger of your own, during which, each time you put something on the clipboard, it will save it to your file. To understand that something has been added to the clipboard, you will have to use a loop during which you will be checking the clipboard content per so many seconds. lets say every 30 seconds. If the Clipboard content is empty or does not contain a specific prefix you have set for your memos, it will then do nothing but wait for another 30 secs till it checks again, if the clipboard is not empty and does contain that prefix it will then append the clipboard text to the memo file. Please check the job attached. It's just a temp solution for exe files. You will have to put the exe file of this job in the Startup folder, so that you do not have to manually start it every time you power on your machine. Hope u find it helpful. (There are two different approaches according to which version of WA you are using. Please make sure the file is created before you run this job)

append text to memo - exe v.3.0.waj append text to memo - exe v.3.1.waj

#4

rasselas

  • Joined: Oct 21, 2012
  • Posts: 2

Mon 10/22/2012 - 0:06

Hello, I would like to know if there is an answer to the question, "Is there a way to wait on user keystrokes without requiring an intervening dialog window"?

 

Example, I usually make it a habit that when writing an automation-task to store my existing clipboard text into a variable, so that when the task is finished, it will automatically restore whatever text was pre-existing in my clipboard.

 

However, some tasks I write will store an intermediate value into the clipboard, and will then wait on me to decide whether that content should be pasted or not... therefore, the task cannot simply overwrite the clipboard (with my original content) until such time as I am sure I no longer need the intermediary value stored in the clipboard (ie., i have pasted or chosen not to paste).


Currently I suppose I would first have to invoke a dialogue window, and then click the ok button, before the program can decide. If it could detect whether I have already pressed ctrl+v then it would know whether it can restore the original contents of the clipboard. (of course that leaves the problem of deciding not to paste...)

 

Thanks for taking the time to ponder on this.

Rasselas

#5

Samantha

  • Joined: Apr 23, 2010
  • Posts: 2326

Tue 10/23/2012 - 11:34

You could use a Wait for Hotkey Action, to have the system wait for your mark to set of.. I'm attaching a sample script with a part of code that you could paste into yours to get things done!

 

Hope this helps!

 

Samantha

(SS)_Wait_for_user_to_make_a_decision.waj

#6
Not a member yet? Register

Copyright 2013 - Softomotive Ltd