1. Keypress question
- Posted by don cole <doncole at pacbell.net> Apr 11, 2007
- 496 views
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
2. Re: Keypress question
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Apr 11, 2007
- 514 views
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)
junk=w32Func(xSystemParametersInfo,{SPI_SETSCREENSAVEACTIVE,new_state,0,update_policy})
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:
constant user32=open_dll("user32.dll") ,xSystemParametersInfo=define_c_func(user32,"SystemParametersInfoA", repeat(C_ULONG,4),C_ULONG)
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
3. Re: Keypress question
- Posted by don cole <doncole at pacbell.net> Apr 12, 2007
- 511 views
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? 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. 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? Thank you for your help. Don Cole
4. Re: Keypress question
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Apr 12, 2007
- 485 views
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
5. Re: Keypress question
- Posted by Hayden McKay <hmck1 at dodo.com.au> Apr 12, 2007
- 480 views
This link like a good start http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=740141&SiteID=1
6. Re: Keypress question
- Posted by Hayden McKay <hmck1 at dodo.com.au> Apr 12, 2007
- 504 views
I was looking for a source I once read that demonstrated how stuff keys into the 8042 keyboard chip. I could'nt find the article I was looking for but I did find this http://72.14.235.104/search?q=cache:HQw5MYjtXeAJ:guideme.itgo.com/atozofc/ch22.pdf+8042+stuff+keys&hl=en&ct=clnk&cd=1
7. Re: Keypress question
- Posted by don cole <doncole at pacbell.net> Apr 12, 2007
- 490 views
- Last edited Apr 13, 2007
Thanks Hayden and CChris, I will take me some time to digest all of this. I'll get back to you. Don Cole