AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED-partly]Keep Screen Off Unless A Specific Key Pressed

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Matrix



Joined: 05 Apr 2008
Posts: 4

PostPosted: Sat Apr 05, 2008 1:15 am    Post subject: [SOLVED-partly]Keep Screen Off Unless A Specific Key Pressed Reply with quote

Hello!

I have used the following code to turn off my monitor:
Code:
#o:: 
    Sleep 01000
    SendMessage, 0x112, 0xF170, 1,, Program Manager 
return


I also want to add functionality that keeps the monitor off unless space bar or some other key is pressed, BUT all other keys keep operating normally.
The reason I want to do this, is that I can continue to control Winamp even when the monitor is off.
Help is appreciated!


Last edited by Matrix on Tue Apr 15, 2008 12:49 am; edited 2 times in total
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 666
Location: MN, USA

PostPosted: Sun Apr 06, 2008 5:52 am    Post subject: Reply with quote

How about changing the Display Properties so that the output is not going to the laptop's LCD? For example, switch to the VGA port (where there presumably is no monitor). I think that would achieve the desired effect.
_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
Matrix



Joined: 05 Apr 2008
Posts: 4

PostPosted: Sun Apr 06, 2008 10:42 am    Post subject: Reply with quote

jaco0646 thanks for your reply.
If I am getting you correctly, you mean creating a script which actually does the same as fn+F5?
Help will be appreciated in creating the script Laughing
Back to top
View user's profile Send private message
Guest






PostPosted: Tue Apr 08, 2008 8:48 pm    Post subject: Reply with quote

Like the Nike slogan implies: Just do it!
Back to top
Matrix



Joined: 05 Apr 2008
Posts: 4

PostPosted: Wed Apr 09, 2008 1:24 am    Post subject: Reply with quote

Quote:
Like the Nike slogan implies: Just do it!

Some trial and error and actually I did do it! Very Happy
A simple loop with the getkeystate solved my problem.
Any way, thanks for your help
Back to top
View user's profile Send private message
Troll
Guest





PostPosted: Wed Apr 09, 2008 1:57 am    Post subject: Reply with quote

No prob Smile
Back to top
Veil



Joined: 01 Apr 2008
Posts: 22
Location: Netherlands

PostPosted: Wed Apr 09, 2008 2:29 am    Post subject: Reply with quote

Please post your script, seems interesting.
Back to top
View user's profile Send private message Send e-mail
Matrix



Joined: 05 Apr 2008
Posts: 4

PostPosted: Tue Apr 15, 2008 12:48 am    Post subject: Reply with quote

After further investigating the script I wrote, I saw it wasn't a good script.
Meaning, while the script was in the loop, the CPU usage climbed to 50%.
The logic of the script was to keep sending the command to shutdown the monitor till one of the keys (space, left mouse button, right mouse button) were pressed:
Code:
^esc::   ; ctrl+esc hotkey that turns off the monitor.
    Sleep 1000   ; Give user a chance to release keys (in case their release would wake up the monitor again).
     Loop
     {
         ; Turn Monitor Off:
         SendMessage, 0x112, 0xF170, 1,, Program Manager   ; 0x112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.      
         ; Note for the above: Use -1 in place of 2 to turn the monitor on.
         ; Use 1 in place of 2 to activate the monitor's low-power mode 
         If ((GetKeyState("Space","P")) Or (GetKeyState("LButton","P")) Or (GetKeyState("Rbutton","P")))
           { 
               SendMessage, 0x112, 0xF170, -1,, Program Manager
               break
           }
      }
return

If anyone knows a way to boost this script into a better one, I would appreciate it.
Thanks,
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 1494

PostPosted: Tue Apr 15, 2008 12:57 am    Post subject: Reply with quote

Code:
^esc::   ; ctrl+esc hotkey that turns off the monitor.
    Sleep 1000   ; Give user a chance to release keys (in case their release would wake up the monitor again).
     Loop
     {
         ; Turn Monitor Off:
         Sleep 1000
         If A_TimeIdlePhyiscal < 2500
         {

           SendMessage, 0x112, 0xF170, 1,, Program Manager   ; 0x112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.     
           ; Note for the above: Use -1 in place of 2 to turn the monitor on.
           ; Use 1 in place of 2 to activate the monitor's low-power mode 
           If ((GetKeyState("Space","P")) Or (GetKeyState("LButton","P")) Or (GetKeyState("Rbutton","P")))
           { 
               SendMessage, 0x112, 0xF170, -1,, Program Manager
               break
           }
         }
      }
return

That should cut down on CPU load and only turn off the monitor a few seconds after the user has done some input.
_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group