PJThys Posted October 28, 2005 Posted October 28, 2005 Is there a safe way to detect when a copy to the clipboard is finished. Afterwards the contents of the clipboard need to be written to a file. This file is then parsed. Snippet: Send("^a^c") $file = FileOpen($Target & "\" & $Test & "TMP.txt", 2) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($file, ClipGet()) FileClose($file) gave me an empty file, only 2 sleep(10000) (one after ^a^c and one before FileClose) gave me results in 4 out of 5 cases, but slows down the process a lot. Then I tried trapping the wait cursor (cursor_id 15) Send("^a^c") MsgBox(48, "", "Wait a moment please", 3) While 1 MouseMove(5, 10) $MouseCursor = MouseGetCursor() If $MouseCursor = "15" Then While 1 MouseMove(5, 10) $MouseCursor = MouseGetCursor() If $MouseCursor = "2" Then ExitLoop 2 WEnd EndIf WEnd $file = FileOpen($Target & "\" & $Test & "TMP.txt", 2) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($file, ClipGet()) FileClose($file) Performance is much better, but it seems not always to trap the wait cursor (I'm not sure that it always appears). Any idea on how to find out whether ^a^c is finished writing to the clipboard? Manualy opening a text document and pasting with ^v always works, but it's rather ugly, and poses problems because of different OS and installed languages on pc's so it's more difficult to save and close notepad (different commands/window titles) Furthermore I'm not sure that the fileclose does not close the file before the clipboard is written completely to the file. Anyone knows if fileclose is waiting till filewrite is finished? Sorry for the long post, but I've been working for 2 weeks on this script and this and the previous post represent the last problems. I could live with it myself, because I discover immediatly when it doesn't run like intended and can try again, but to give it to our secretaries when it is not 'foolproof' is something else Thx in advance Peter
flyingboz Posted October 28, 2005 Posted October 28, 2005 (edited) long winded ramble re: long cut/paste operation detectionYou didn't mention pertinent information re: what app you're copying from - or what text is being copied / parsed, or if there are a mininum number of bytes being grabbed. Any of those factors may be leveraged.Any markup language has tags , etc. etc, etc. If you're using any COM-aware app you may be able to utilize COM functionality - IE and Office apps expose methods / properties you can use to increase the reliabilityYou could also "salt the shaft" , append an unusual string to the text prior to the ^a^c, and then loop your ClipGet() until the salt appears. $salt = "unusual_append_string" While 1 $text = ClipGet() If StringInStr($text,$salt) then ExitLoop Sleep(500) WendAnother methodology might involve a third party clipboard util, which you could salt, then get the clipboard -1 entry after the last one occurs.Just a few ideas off the cuff. Edited October 28, 2005 by flyingboz Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
PJThys Posted October 29, 2005 Author Posted October 29, 2005 Thanx for your reply. The application is Questionmark Perception, a program to make electronic tests. It is a black box to me. A test consists of between 160 and 200 questions. Each separate question is made in a separate window where a lot of extra information has to be entered for electronic correction of the test. As author of a test we can make the test with QMP, but reporting or debugging the test is difficult. If we forget to fill in a correct answer to a question, we only can see that by trying out the test (fill in all questions) and at the end of the test we push the continue button and the test comes with the correct answers. Then we can check if every question has an answer. The size of the copy is unclear to me. If I cut and paste to a text editor the result is about 75 kb, but all pictures are of course removed. That's no problem for my purpouses. If I try to paste to Word it takes about 15 minutes and results in a word doc of 2 Mb. To parse that is very difficult. The size will be between 0.1 and 2 Mb I couldn't tell exactly. Writing a string to the test window is impossible, I could only write such a string to the end off the last question (which of course we will forget to remove before final publication of the test I Only want to be able to produce: 1 Flat text file with questions and answers (find spelling errors) 2 Flat text file with questionnumber and answer (to give to the students later: these would have been your correct answers) and this shows me the questions where we forgot to enter an answer 3 CSV file with questions, answers and topics for processing statistics about test (20 questions about respiratory system, 30 questions about old people, etc) I can produce all these files from the copied flat text file. I'm rewriting my script now. I had a gui where some parameters could be entered, it used messageloop-mode. I'm rewriting it to use on-event mode, suspecting that that might be the reason why my cursor is not always trapped! and then my second solution might work always btw QMP did a nice job in preventing students to cut and past or copy the final published test, I was not able to find a tool to copy the final test, when for example kleptomania, a sofisticated screengrabber was loaded, QMP refused to start, stating that I first had to remove kleptomania from memory!!
Confuzzled Posted October 29, 2005 Posted October 29, 2005 Some ideas:Does the QMP program support Windows Accessibility functionality (output for the blind and hearing impaired)? If it does, then there will be some sort of secondary output mechanism that you should be able to tap into somewhere.Increase your memory availability for the program to function quicker by shutting down unnecessary programs running.Between clipboard operations flush the clipboard buffer by copying a single character to the clipboard.I hope you are not developing the ultimate exam cheat program!
PJThys Posted October 29, 2005 Author Posted October 29, 2005 No, no more exams at my age (54), We are develloping exams! As far as I know there is no accessibility functionality
Confuzzled Posted October 29, 2005 Posted October 29, 2005 No, no more exams at my age (54), We are developing exams!As far as I know there is no accessibility functionality Why not approach the developers of QMP and ask for added functionality to make your life a little less difficult? I'm sure if they value their product they will make it as easy as possible for others to use it. They may already have added tools for educators, or be happy to use you as a development tester while they develop them...
flyingboz Posted October 30, 2005 Posted October 30, 2005 (edited) ..difficult to cut/paste textYou may wish to invest in a copy of www.screenocr.com - i have used it to defeat other obstinate programs.copy / paste buffer 75k au3 clipget() at one time had a hard-coded limit of 64k - you may wish to check the current version docs to see what the limit is now and ensure that you aren't running into a size limit - IIRC, the size limit was due to a win95 compatibility issue. Edited October 30, 2005 by flyingboz Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
PJThys Posted October 31, 2005 Author Posted October 31, 2005 (edited) 'flyingboz' , you set me on the right track! I gave up watching cursorchange, too tricky. Clipboard size was not the problem, throwing in 2 times a 10 seconds wait would solve the problem. But waiting 20 seconds for a situation which only seems to happen in 20% of the cases is a shame. So I worked on your SALT idea, bij testing ClipGet() for the occurrence of a word I was sure would be in the clipboard. This seems to have solved the problem. My code is now like this: (where "comment" is a word I know exists multiple times in the copied text) Send("^a^c") ;copy all to clipboard While Not StringInStr(ClipGet(), "comment ") ;wait till "comment " is found in clipboard ;(assuming that all text is copied to clipboard then) Sleep(10) WEnd Allthough this word occurs a lot in the clipboard, StringInStr(Clipget(),"comment") does not seem to start before the clipboard is written. Can anyone confirm that behavior? I've tested it 20 times now and found no more 'timing errors' Peter Edited October 31, 2005 by PJThys
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now