Announcement

Collapse
No announcement yet.

sendkkey for monitor turnoff

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • sendkkey for monitor turnoff

    I'm trying to add these buttons to the autoit script but I can not, someone could help me "MONITOR_OFF" , "MONITOR_ON" , "MONITOR_ESC"

    Code:
    #NoTrayIcon
    
    ;*****************************************connexion  RR**************************************
    Global Const $StructDef_COPYDATA = "ptr;dword;ptr"
    ;Global Const $WM_COPYDATA = 0x4A
    ;Global Const $WM_CLOSE = 0x10
    Global Const $STRUCTDEF_AU3MESSAGE = "char[255]"
    
    $rr = ObjCreate("RoadRunner.SDK")
    
    Global Const $lciWM_SYSCommand = 274
    Global Const $lciSC_MonitorPower = 61808
    Global Const $lciPower_Off = 2
    Global Const $lciPower_On = -1
    
    Global $MonitorIsOff = False
    
    HotKeySet("{F11}", "_Monitor_OFF")
    HotKeySet("{F10}", "_Monitor_ON")
    HotKeySet("{Esc}", "_Quit")
    
    ;~ MsgBox(64, "Monitor On/Off", "Press F11 to turn off the monitor." & @LF & _
    ;~                             "Press F10 to turn on the monitor back." & @LF & _
    ;~                             "Press ESC to turn on the monitor and exit program.")
    
    While 1
        Sleep(10)
    WEnd
    
    Func _Monitor_ON()
        $MonitorIsOff = False
        Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
    
        DllCall('user32.dll', 'int', 'SendMessage', _
                                                    'hwnd', $Progman_hwnd, _
                                                    'int', $lciWM_SYSCommand, _
                                                    'int', $lciSC_MonitorPower, _
                                                    'int', $lciPower_On)
    EndFunc
    
    Func _Monitor_OFF()
        $MonitorIsOff = True
        Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
    
        While $MonitorIsOff = True
            DllCall('user32.dll', 'int', 'SendMessage', _
                                                        'hwnd', $Progman_hwnd, _
                                                        'int', $lciWM_SYSCommand, _
                                                        'int', $lciSC_MonitorPower, _
                                                        'int', $lciPower_Off)
            _IdleWaitCommit(0)
            Sleep(20)
        WEnd
    EndFunc
    
    Func _IdleWaitCommit($idlesec)
        Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword")
        DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo))
        DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
        Do
            $iSave = DllStructGetData ($LastInputInfo, 2)
            Sleep(60)
            DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
        Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec Or $MonitorIsOff = False
        Return DllStructGetData ($LastInputInfo, 2)-$iSave
    EndFunc
    
    Func _Quit()
        _Monitor_ON()
        Exit
     EndFunc
    
     ;**********************************************connexion  RR*************************************************
    ;***********************************************************************************************************
    
    ; Message Handler
    Func _GUIRegisterMsgProc($hWnd, $MsgID, $WParam, $LParam)
    	If $MsgID = $WM_COPYDATA Then
    		; We Recived a WM_COPYDATA Message
    		; $LParam = Poiter to a COPYDATA Struct
    		$vs_cds = DllStructCreate($StructDef_COPYDATA, $LParam)
    		; Member No. 3 of COPYDATA Struct (PVOID lpData;) = Pointer to Costum Struct
    		$vs_msg = DllStructCreate($STRUCTDEF_AU3MESSAGE, DllStructGetData($vs_cds, 3))
    
    		$SciTECmdLen = DllStructGetData($vs_cds, 2)
    		$cmd = StringLeft(DllStructGetData($vs_msg, 1), $SciTECmdLen)
    
    		; Display what we have recived
    		;MsgBox(0, "Test String", $cmd)
    
    	ElseIf $MsgID = $WM_CLOSE Then
    	; We Recived a WM_CLOSE Message
    
    	EndIf
     EndFunc ;==>_GUIRegisterMsgProc
    
     Exit

  • #2
    If you don't use rr for send these commands, just comment the RR object !

    Code:
    #NoTrayIcon
    
    ;~ ;*****************************************connexion  RR**************************************
    ;~ Global Const $StructDef_COPYDATA = "ptr;dword;ptr"
    ;~ ;Global Const $WM_COPYDATA = 0x4A
    ;~ ;Global Const $WM_CLOSE = 0x10
    ;~ Global Const $STRUCTDEF_AU3MESSAGE = "char[255]"
    
    ;$rr = ObjCreate("RoadRunner.SDK")
    
    Global Const $lciWM_SYSCommand = 274
    Global Const $lciSC_MonitorPower = 61808
    Global Const $lciPower_Off = 2
    Global Const $lciPower_On = -1
    
    Global $MonitorIsOff = False
    
    HotKeySet("{F11}", "_Monitor_OFF")
    HotKeySet("{F10}", "_Monitor_ON")
    HotKeySet("{Esc}", "_Quit")
    
    ;~ MsgBox(64, "Monitor On/Off", "Press F11 to turn off the monitor." & @LF & _
    ;~                             "Press F10 to turn on the monitor back." & @LF & _
    ;~                             "Press ESC to turn on the monitor and exit program.")
    
    While 1
        Sleep(10)
    WEnd
    
    Func _Monitor_ON()
        $MonitorIsOff = False
        Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
    
        DllCall('user32.dll', 'int', 'SendMessage', _
                                                    'hwnd', $Progman_hwnd, _
                                                    'int', $lciWM_SYSCommand, _
                                                    'int', $lciSC_MonitorPower, _
                                                    'int', $lciPower_On)
    EndFunc
    
    Func _Monitor_OFF()
        $MonitorIsOff = True
        Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
    
        While $MonitorIsOff = True
            DllCall('user32.dll', 'int', 'SendMessage', _
                                                        'hwnd', $Progman_hwnd, _
                                                        'int', $lciWM_SYSCommand, _
                                                        'int', $lciSC_MonitorPower, _
                                                        'int', $lciPower_Off)
            _IdleWaitCommit(0)
            Sleep(20)
        WEnd
    EndFunc
    
    Func _IdleWaitCommit($idlesec)
        Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword")
        DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo))
        DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
        Do
            $iSave = DllStructGetData ($LastInputInfo, 2)
            Sleep(60)
            DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
        Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec Or $MonitorIsOff = False
        Return DllStructGetData ($LastInputInfo, 2)-$iSave
    EndFunc
    
    Func _Quit()
        _Monitor_ON()
        Exit
    EndFunc
    
    ;~  ;**********************************************connexion  RR*************************************************
    ;~ ;***********************************************************************************************************
    
    ;~ ; Message Handler
    ;~ Func _GUIRegisterMsgProc($hWnd, $MsgID, $WParam, $LParam)
    ;~ 	If $MsgID = $WM_COPYDATA Then
    ;~ 		; We Recived a WM_COPYDATA Message
    ;~ 		; $LParam = Poiter to a COPYDATA Struct
    ;~ 		$vs_cds = DllStructCreate($StructDef_COPYDATA, $LParam)
    ;~ 		; Member No. 3 of COPYDATA Struct (PVOID lpData;) = Pointer to Costum Struct
    ;~ 		$vs_msg = DllStructCreate($STRUCTDEF_AU3MESSAGE, DllStructGetData($vs_cds, 3))
    
    ;~ 		$SciTECmdLen = DllStructGetData($vs_cds, 2)
    ;~ 		$cmd = StringLeft(DllStructGetData($vs_msg, 1), $SciTECmdLen)
    
    ;~ 		; Display what we have recived
    ;~ 		;MsgBox(0, "Test String", $cmd)
    
    ;~ 	ElseIf $MsgID = $WM_CLOSE Then
    ;~ 	; We Recived a WM_CLOSE Message
    
    ;~ 	EndIf
    ;~  EndFunc ;==>_GUIRegisterMsgProc
    
     ;Exit
    Into the While loop, it's better to use a bigger sleep (100) (CPU will you say thanks)
    Last edited by pierrotm777; 03-07-2014, 07:57 AM.

    Comment


    • #3
      I want this script to turn off the monitor at night, using the touch screen, I do not use keyboard

      why I wanted to put those 3 buttons ...

      for example

      I would do a skin for this RR is working, press a button and turn off the monitor
      B,0,4,85,54,"LOAD;MONITOROFF.SKIN||MY COMMAND TO F11"

      then when you want to turn on the monitor, this command would

      L01,-2,2,802,598,255,255,255,18,"Arial","EXEC;EXIT||MY COMMAND TO F10","",


      the idea would be something like

      Comment


      • #4
        may be is this a reason for you?:
        http://www.nirsoft.net/utils/nircmd.html
        RR-Skin: BMW OpenBM Skin for E39 [never ending progress :-(]
        RR-Plugin: IBusCommunicatoRR new Updates

        Comment


        • #5
          but that little software only have turn off monitor or have too turn on monitor , let me see

          i only need add

          those hotkey that work with RR to this autoit

          HotKeySet("{F11}", "_Monitor_OFF")
          HotKeySet("{F10}", "_Monitor_ON")
          HotKeySet("{Esc}", "_Quit")


          with sendkey or something
          Last edited by mikeeps2; 03-07-2014, 03:57 PM.

          Comment


          • #6
            no , that small software that does not work for me what I want

            Comment


            • #7
              I think that this code will run well !
              Create 3 buttons:
              SENDMSG;MONITOR;MONITOR_ON
              SENDMSG;MONITOR;MONITOR_OFF
              SENDMSG;MONITOR;MONITOR_EXIT

              Run the script as:
              "Run;$skinpath$Scripts\MonitorOnOff.exe"

              But when the monitor is off , how do you click on the button ?

              Code:
              #NoTrayIcon
              #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
              #AutoIt3Wrapper_outfile=MonitorOnOff.exe
              #AutoIt3Wrapper_Compression=4
              #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
              
              ;~ ;*****************************************connexion  RR**************************************
              Global Const $StructDef_COPYDATA = "ptr;dword;ptr"
              Global Const $WM_COPYDATA = 0x4A
              Global Const $WM_CLOSE = 0x10
              Global Const $STRUCTDEF_AU3MESSAGE = "char[255]"
              
              ;create SDK for COM with RR.  This must be done ONLY once per script
              $rr = "NIL"
              $F = WinExists("RoadRunner")
              If $F = 0 Then MsgBox(0, "Error", "Google Maps need a RideRunner" & @CRLF & _
              			"process to run !!!", 5)
              If $F = 1 Then
                  $rr = ObjCreate("RideRunner.SDK")
              Else
              	_Quit()
              EndIf
              
              Global Const $lciWM_SYSCommand = 274
              Global Const $lciSC_MonitorPower = 61808
              Global Const $lciPower_Off = 2
              Global Const $lciPower_On = -1
              
              Global $MonitorIsOff = False
              
              Dim $cmd
              
              HotKeySet("{F11}", "_Monitor_OFF")
              HotKeySet("{F10}", "_Monitor_ON")
              HotKeySet("{Esc}", "_Quit")
              
              ;~ MsgBox(64, "Monitor On/Off", "Press F11 to turn off the monitor." & @LF & _
              ;~                             "Press F10 to turn on the monitor back." & @LF & _
              ;~                             "Press ESC to turn on the monitor and exit program.")
              
              ; Create Reciver window
              $hwmd_Reciver = GUICreate("MONITOR")
              ; Register Windows Messages
              GUIRegisterMsg($WM_COPYDATA, "_GUIRegisterMsgProc")
              GUIRegisterMsg($WM_CLOSE, "_GUIRegisterMsgProc")
              
              While 1
                 	If $cmd = "MONITOR_ON" Then
              	  $cmd = ""
              		Send("{F10}")
              	Endif
              
              	If $cmd = "MONITOR_OFF" Then
              	  $cmd = ""
              		Send("{F11}")
              	Endif
              
              	If $cmd = "MONITOR_EXIT" Then
              	  $cmd = ""
              		Send("{ESC}")
              	Endif
              	sleep(100)
              WEnd
              
              Func _Monitor_ON()
                  $MonitorIsOff = False
                  Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
              
                  DllCall('user32.dll', 'int', 'SendMessage', _
                                                              'hwnd', $Progman_hwnd, _
                                                              'int', $lciWM_SYSCommand, _
                                                              'int', $lciSC_MonitorPower, _
                                                              'int', $lciPower_On)
              EndFunc
              
              Func _Monitor_OFF()
                  $MonitorIsOff = True
                  Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
              
                  While $MonitorIsOff = True
                      DllCall('user32.dll', 'int', 'SendMessage', _
                                                                  'hwnd', $Progman_hwnd, _
                                                                  'int', $lciWM_SYSCommand, _
                                                                  'int', $lciSC_MonitorPower, _
                                                                  'int', $lciPower_Off)
                      _IdleWaitCommit(0)
                      Sleep(20)
                  WEnd
              EndFunc
              
              Func _IdleWaitCommit($idlesec)
                  Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword")
                  DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo))
                  DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
                  Do
                      $iSave = DllStructGetData ($LastInputInfo, 2)
                      Sleep(60)
                      DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
                  Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec Or $MonitorIsOff = False
                  Return DllStructGetData ($LastInputInfo, 2)-$iSave
              EndFunc
              
              Func _Quit()
                  _Monitor_ON()
                  Exit
              EndFunc
              
              ;**********************************************connexion  RR*************************************************
              ;***********************************************************************************************************
              
              ; Message Handler
              Func _GUIRegisterMsgProc($hWnd, $MsgID, $WParam, $LParam)
              	If $MsgID = $WM_COPYDATA Then
              		; We Recived a WM_COPYDATA Message
              		; $LParam = Poiter to a COPYDATA Struct
              		$vs_cds = DllStructCreate($StructDef_COPYDATA, $LParam)
              		; Member No. 3 of COPYDATA Struct (PVOID lpData;) = Pointer to Costum Struct
              		$vs_msg = DllStructCreate($STRUCTDEF_AU3MESSAGE, DllStructGetData($vs_cds, 3))
              
              		$SciTECmdLen = DllStructGetData($vs_cds, 2)
              		$cmd = StringLeft(DllStructGetData($vs_msg, 1), $SciTECmdLen)
              
              		; Display what we have recived
              		;MsgBox(0, "Test String", $cmd)
              
              	ElseIf $MsgID = $WM_CLOSE Then
              	; We Recived a WM_CLOSE Message
              
              	EndIf
               EndFunc ;==>_GUIRegisterMsgProc
              Last edited by pierrotm777; 03-08-2014, 12:10 PM.

              Comment


              • #8
                when try to compile , or run show this error

                C:\Program Files\RideRunner\Skins\AUTOMATION\Scripts\MONITORO NOFF\MonitorOnOff.au3 (50) : ==> Unterminated string.:
                Send("{F10})


                i think for turn on again , use

                L01,-2,2,802,598,255,255,255,18,"Arial","EXEC;EXIT||SEN DMSG;MONITOR;MONITOR_ON","",

                Comment


                • #9
                  => " <= insert this behind }
                  RR-Skin: BMW OpenBM Skin for E39 [never ending progress :-(]
                  RR-Plugin: IBusCommunicatoRR new Updates

                  Comment


                  • #10
                    Sorry , the post 7 is updated !

                    Comment


                    • #11
                      perfect i test and work perfect now

                      i use this

                      botton for turn off monitor

                      B,0,4,85,54,"MONITOR_OFF",

                      button for turn on monitor

                      L01,-2,2,802,598,255,255,255,18,"Arial","EXEC;MONITOR_O N","",

                      then into exectbl this

                      "MONITOR_OFF","LOAD;SCREEN_SAVER.SKIN||Run;$skinpa th$Scripts\MONITORONOFF\MonitorOnOff.exe||SENDMSG; MONITOR;MONITOR_OFF"
                      "MONITOR_ON","SENDMSG;MONITOR;MONITOR_ON||SENDMSG; MONITOR;MONITOR_EXIT||EXIT"


                      then I'm going to test on my touch screen
                      Last edited by mikeeps2; 03-08-2014, 02:48 PM.

                      Comment


                      • #12
                        How can you use these command if the screen is off . The touch screen continue to run when the screen is off ?

                        Comment


                        • #13
                          Originally posted by pierrotm777 View Post
                          How can you use these command if the screen is off . The touch screen continue to run when the screen is off ?
                          The touchscreen is a separate USB input device.

                          So yes will work without the monitor being on.

                          In most cases anyway, unless it is not getting power from the USB.

                          Comment


                          • #14
                            Is that a permanent off or just energy-saving off? Because I tried that before and couldnt turn off the monitor without triggering the energy-saving off. So whatever I did on an USB device, like a controller for just changing volume, the monitor would turn on anyway, if I gave input over a USB device, which made it useless for me.
                            So you dont really need an on-command, because any touching of the touchscreen would turn the screen on again.

                            Comment


                            • #15
                              Another mode exist ! Standby

                              Global Const $lciPower_Standby = 1

                              Comment

                              Working...
                              X