Re: Keypress question

new topic     » goto parent     » topic index » view thread      » older message » newer message

don cole wrote:
> 
> CChris wrote:
> > 
> > don cole wrote:
> > > 
> > > Hello Sverybody,
> > > 
> > >    How can I simulate a keypress into my program?
> > > You know, a lot of computers go into screen saver or shut down after a
> > > period
> > > of time if no keypress is made. I would like to override this for store
> > > window
> > > displays. 
> > > 
> > > Don Cole
> > 
> > Isn't it simpler to just deactivate the screensaver?
> > You can do this by calling (using the win32lib syntax)
> > }}}
<eucode>
> >
> > junk=w32Func(xSystemParametersInfo,{SPI_SETSCREENSAVEACTIVE,new_state,0,update_policy})
> > </eucode>
{{{

> > with <i>new_state</i> set to 0. Enable again by calling with
> > <i>new_state</i>=1.
> > <i>update_policy</i> is either 0 (no user profile update), 1 (update
> > profile)
> >  or 2 (update and broadcast). SPIF_INIUPDATE is defined as 1 and
> >  SPIF_SENDCHANGE as 2.
> > If you don't use win32lib, replace w32Func by c_func and wrap the API
> >  as follows:
> > }}}
<eucode>
> > constant
> > user32=open_dll("user32.dll")
> > ,xSystemParametersInfo=define_c_func(user32,"SystemParametersInfoA",
> >                                       repeat(C_ULONG,4),C_ULONG)
> > </eucode>
{{{

> > Replace A by W on Unicode platforms.
> > 
> > The problem with sending a simulated mouse/keyboard events is that there is
> >  a setting to prevent these simulated events to affect the screensaver. If 
> > you are bent on simulating input, please read the doc to the SendInput()
> >  API function. In particular, Vista puts additional restrictions to this.
> > 
> > Last but not least, SPI_SETSCREENSAVEACTIVE is 17.
> > 
> > HTH
> > CChris
> 
> Thank you CChris,
> 
> I'm testing your code.
> 
> Windows XP Control Panel - Display - Screen Saver Allows you to set the wait
> time up to 9999 minuets max. This is about seven days which is sufficient for
> my purposes. Doesn't you code do about the same thing but longer?
> 

The SystemParametersInfo() API is an unified interface presented by Windows 
so as to hide the BIOS differences. What the function does under the hood
 may differ from machine to machine. In a way, you are right - setting the 
timer to a huge delay is effectively disabling it.


> I am using this code on a lot of different computers. My main concern is that
> some computers go into hibernate mode and turn off the screen. To change this
> setting you have to go into the bios of each computer. This I don't want to
> do. 

In a perfect world, the interface takes care of the BIOS differences. Since 
neither M$ nor the world are perfect, I can't guarantee you that the code
would work equally well on all computer BIOSes and Windows builds. You'd 
have to dig into MSDN's knowledge base to get specific information if you 
observe some unexpected behaviour.

> I want to do it with code if possible. I have one computer I have set the
> Screen Save wait time to 9999 mins. after about 5 mins. the screen goes blank.
> I know I could probably go into the bios and change this. Again I don't want
> to have to do this with every different type of computer. I have Dells,
> Compaq,
> Hewlett Packard and generic computers I put in my store window. Will your code
> work on all bios if they are set to hibernate?
> 

I don't know for sure, but in theory it should.
However, similar code with different values of the setting
(the first parameter) will guarantee it. Try SPI_SETLOWPOWERACTIVE (=85) and 
SPI_SETPOWEROFFACTIVE (=86) instead of SPI_SETSCREENSAVEACTIVE, which you'll
have to use anyway. Issue all three calls, and everything should work as
 expected. Normally, the low power/power off phases shouldn't occur if
 there's no screen saving; in that sense, disabling is not the same as
 setting to a huge delay. I cannot test this, you'll have to experiment.

> Thank you for your help.
> 
> 
> Don Cole

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu