Page 1 of 1

intercepting printer events in windows

Posted: Wed Jun 25, 2014 2:45 pm
by magice
I'm not sure if what I want to do is possible, but I am sure that if it is someone here will know how it is done. I want a small app to pop up every time someone begins the print process, (after ctrl+p/file-print etc. but before hitting the ok button) Is there any interceptable messages from windows that can be used to trigger an app?

Re: intercepting printer events in windows

Posted: Wed Jun 25, 2014 2:46 pm
by Klaus
Hi Magice,

I don't think this can be done without an external!


Best

Klaus

Re: intercepting printer events in windows

Posted: Wed Jun 25, 2014 3:54 pm
by magice
Well, that is not good news. I guess i need to issue a challenge to all the creative thinkers on this forum to find a way. After all this is of the utmost importance. An office prank hangs in the balance. My boss is always complaining that the office printer hates him, as it gives him but no one else problems. So, it is only natural that when he prints something the printer should inundate him with short and bald jokes. :twisted:

Re: intercepting printer events in windows

Posted: Wed Jun 25, 2014 7:33 pm
by Simon
For Win
You can watch for the memory usage of spoolsv.exe in the processes.
get shell("tasklist /fo csv")

Simon

Re: intercepting printer events in windows

Posted: Wed Jun 25, 2014 7:53 pm
by magice
Simon wrote:For Win
You can watch for the memory usage of spoolsv.exe in the processes.
get shell("tasklist /fo csv")

Simon
Good thought, but since it opens a console window every time it runs, it would be impractical to continually poll for that data. Still. it is more than I have come up with. I think, unfortunately, Klaus is right. (as usual)

Re: intercepting printer events in windows

Posted: Wed Jun 25, 2014 8:52 pm
by Simon
no no...
set the hideConsoleWindows to true

Simon

Re: intercepting printer events in windows

Posted: Wed Jun 25, 2014 10:38 pm
by magice
Simon wrote:no no...
set the hideConsoleWindows to true

Simon
Nice! It is a little tricky because of inconsistency but I think I can make it work. It seems to occasionally spike on its own so straight ">" evaluation is too sensitive. I just need to work out an acceptable range of difference between the idle and print modes.

Thank you.

Re: intercepting printer events in windows

Posted: Wed Jun 25, 2014 10:58 pm
by Simon
Definitely should add sound...
What would be creepier?

OH OH... open notepad and use VBscript to type him a note then taskkill it :)

Re: intercepting printer events in windows

Posted: Thu Jun 26, 2014 12:31 pm
by magice
Simon wrote:Definitely should add sound...
What would be creepier?

OH OH... open notepad and use VBscript to type him a note then taskkill it :)
Dude! that is awesome! I was going to do it all with revSpeak but I like that even better. I have everyone in the office in on it. They are all going to deny hearing or seeing anything. :twisted:

Re: intercepting printer events in windows

Posted: Thu Jun 26, 2014 3:32 pm
by magice
After extensive testing (at least 1 hour) :roll: I have determined that Simon's technique will work perfectly for my application. However, for anyone reading this in the future, looking to write a more practical app, it is not perfect. On my machine a difference of 70k bytes of memory usage is the lowest I seem to be able to look for without getting false triggers. (I suspect this will change from machine to machine) This results in about 1 in twenty missed triggers. I actually set it for 100, and it adds a random factor where it only triggers about one third of the time. Anyone wanting to use this technique for an app that requires reliability will be disappointed (so Klaus is correct!) but for my app, Simon is the man!

Re: intercepting printer events in windows

Posted: Fri Jun 27, 2014 5:12 pm
by magice
Just an update. (Mostly for Simon)

We spent the afternoon coming up with a list of 50 different "short" and "bald" jokes/comments all told from the perspective of a angry printer with a bad attitude. Each time the script is triggered by the spoolsv.exe memory spike, the last line of the text file is read into a variable and then deleted from the file. Then based on a random number there is a 80% chance that it will revSpeak, and a 20% chance that it will open notepad and get typed out. When the text file is finally empty, it will print 50 copies of a particularly unflattering picture of him hurling into a trash can from last years Christmas party. (The trash can just happens to be beside the evil printer) In big letters across the picture it says "You splashed me you midget q-ball bastard. I will never forgive you." So far today it has gone off 6 times that we know of. We act as if we see and hear nothing. The hardest part of this project is keeping a straight face.

Re: intercepting printer events in windows

Posted: Fri Jun 27, 2014 7:56 pm
by Simon
WICKED!
Really, 6 times is enough to get him really wound up.
Great work!

To keep this on a liveCode learning topic

Code: Select all

sort lines of field 1 by random(the number of lines of field 1)
repeat for each line tLine of field 1
etc.
You get a random list :)

How long are you going to run this?

Simon

Re: intercepting printer events in windows

Posted: Fri Jun 27, 2014 8:06 pm
by magice
Simon wrote:WICKED!
Really, 6 times is enough to get him really wound up.
Great work!

To keep this on a liveCode learning topic

Code: Select all

sort lines of field 1 by random(the number of lines of field 1)
repeat for each line tLine of field 1
etc.
You get a random list :)

How long are you going to run this?

Simon
We decided not to randomize the list because some of the things need to be said in order, and this also gives us a finishing point. Once the list is empty and the print comes out the gag is over....especially since he knows that picture came from my phone. :twisted: