intercepting printer events in windows

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

intercepting printer events in windows

Post by magice » Wed Jun 25, 2014 2:45 pm

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?

Klaus
Posts: 14205
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: intercepting printer events in windows

Post by Klaus » Wed Jun 25, 2014 2:46 pm

Hi Magice,

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


Best

Klaus

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: intercepting printer events in windows

Post by magice » Wed Jun 25, 2014 3:54 pm

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:

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: intercepting printer events in windows

Post by Simon » Wed Jun 25, 2014 7:33 pm

For Win
You can watch for the memory usage of spoolsv.exe in the processes.
get shell("tasklist /fo csv")

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: intercepting printer events in windows

Post by magice » Wed Jun 25, 2014 7:53 pm

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)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: intercepting printer events in windows

Post by Simon » Wed Jun 25, 2014 8:52 pm

no no...
set the hideConsoleWindows to true

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: intercepting printer events in windows

Post by magice » Wed Jun 25, 2014 10:38 pm

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: intercepting printer events in windows

Post by Simon » Wed Jun 25, 2014 10:58 pm

Definitely should add sound...
What would be creepier?

OH OH... open notepad and use VBscript to type him a note then taskkill it :)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: intercepting printer events in windows

Post by magice » Thu Jun 26, 2014 12:31 pm

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:

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: intercepting printer events in windows

Post by magice » Thu Jun 26, 2014 3:32 pm

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!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: intercepting printer events in windows

Post by magice » Fri Jun 27, 2014 5:12 pm

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: intercepting printer events in windows

Post by Simon » Fri Jun 27, 2014 7:56 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: intercepting printer events in windows

Post by magice » Fri Jun 27, 2014 8:06 pm

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:

Post Reply