Jump to content

how to detect when user has pressed a key


Draygoes
 Share

Recommended Posts

Im building a moniter sleeper program. This is my code so far...

Func _Mononoff()
Opt("WinTitleMatchMode", 4)
$hwnd = WinGetHandle("classname=Progman")
$user32 = DllOpen("user32.dll")
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1
DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
Sleep(90000)

endfunc




_mononoff()

The problem is, the moniter is activated when the user presses a key but the program is still running. I need the program to be able to tell when the user presses the key or moves the mouse so it can exit. I have no idea how to go about doing this. I cant find much info in the help file about that.

Could anyone give me an example of the code?

thx

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Did I say something wrong?

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

My version i guess...i use it in school sometimes..

Opt("WinTitleMatchMode", 4)
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)

Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1
Global $Msg = "Idle"

HotKeySet("^!o", "_On")
HotKeySet("^!f", "_Off")
HotKeySet("^!i", "_Idle")
HotKeySet("^!e", "_Bye")

$menu = TrayCreateMenu("Help")
$on = TrayCreateItem("Monitor On" & @TAB & "Ctrl+Alt+O", $menu)
$off = TrayCreateItem("Monitor Off" & @TAB & "Ctrl+Alt+F", $menu)
$idle = TrayCreateItem("Monitor Idle" & @TAB & "Ctrl+Alt+I", $menu)
$Quititem = TrayCreateItem("Exit" & @TAB & "Ctrl+Alt+E", $menu)
$hwnd = WinGetHandle("classname=Progman")
$user32 = DllOpen("user32.dll")

While 1
    Sleep(1)
WEnd

Func _On()
    $Msg = "On"
    While $Msg = "On"
        DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_On)
        Sleep(1)
    WEnd
EndFunc   ;==>_On
Func _Off()
    $Msg = "Off"
    While $Msg = "Off"
        DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
        Sleep(1)
    WEnd
EndFunc   ;==>_Off
Func _Idle()
    $Msg = "Idle"
EndFunc   ;==>_Idle
Func _Bye()
    $Msg = "Idle"
    DllClose($user32)
    Exit
EndFunc   ;==>_Bye
Link to comment
Share on other sites

Thanks but im looking for a way to tell when they have pressed any key on the keyboard. For example,

If userpressesanykey Then

Exit

Endif

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...