Jump to content

Recommended Posts

Posted (edited)

What does Monoff4.exe actually do? Turn of your monitor?

If that's the case, there's a really simple alternative, which requires no external programs to operate(this is code taken from an example in the helpfile regarding _SendMessage, which I modified a little):

#include <misc.au3>

While 1
    If _IsPressed("23") Then
        _ToggleMonitor(0)
    EndIf
    Sleep(250)
WEnd

Func _ToggleMonitor($State)
    Local Const $Off = 2, $On = -1
    Local Const $WM_SYSCOMMAND = 274
    Local Const $SC_MONITORPOWER = 61808
    Local $oldOpt = Opt("WinTitleMatchMode", 4)
    Local $hWnd = WinGetHandle("[CLASS:Progman]")
    Opt("WinTitleMatchMode", $oldOpt)
    If $State Then
        _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, $On)
    Else
        _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, $Off)
    EndIf
EndFunc

Edit:

I noted that when you release the key the monitor automatically turns back on(probably because of when you release the key it triggers a keypress and that turns the monitor(s) back on), so there's no need to turn it back on with _ToggleMonitor(1) again. :)

Edited by FreeFry
Posted (edited)

see this #450718

Sorry guys, I'm about a week into AutoIt, and that script is way over my head... Could someone post an example of how I could use it in this context? The script I've been using is simply a matter of running it, pressing the key, and up pops a message box with the info... Something like that would be nice, if someone has the time. Edited by Xichael
Posted

What does Monoff4.exe do?

If it turns the monitor off, then the script I posted should work(press and hold the end key to turn it off, release and it should turn back on).

Posted (edited)

What does Monoff4.exe actually do?... there's a really simple alternative...

Thanks FreeFry, I'll give it a try, and hopefully eventually get it working with the MediaDirect button. I'd much rather turn off the monitor using AutoIt... Edited by Xichael
Posted

Run this:

Global Const $WH_KEYBOARD_LL = 13
Global $hHook
Global $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
Global $hmod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", _
        $WH_KEYBOARD_LL, "ptr", DllCallbackGetPtr($hStub_KeyProc), "hwnd", $hmod[0], "dword", 0)
Global $buffer = ""

While 1
    Sleep(10)
WEnd

Func EvaluateKey($keycode)
    Msgbox(0, 'Key Pressed', '$keyCode = ' & $keyCode & @CRLF & 'Chr($keyCode) = ' & Chr($keyCode))
    
    If $keyCode = 65 then 
        Msgbox(0, 'Winner!', 'Somebody pressed A')
    EndIf
EndFunc  ;==>EvaluateKey

Func _KeyProc($nCode, $wParam, $lParam)
    Local $ret, $KEYHOOKSTRUCT
    If $nCode < 0 Then
        $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], _
                "int", $nCode, "wparam", $wParam, "lparam", $lParam)
        Return $ret[0]
    EndIf
    If $wParam = 256 Then
        $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr", $lParam)
        EvaluateKey(DllStructGetData($KEYHOOKSTRUCT, 1))
    EndIf
    $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], _
            "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    Return $ret[0]
EndFunc  ;==>_KeyProc

Func OnAutoItExit()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0])
    DllCallbackFree($hStub_KeyProc)
EndFunc  ;==>OnAutoItExit
And see what the $keyCode is equal when you press the button. Then, change the 65 to whatever that was and you should be able to call a function whenever the button you want is pressed.
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Posted

Thanks Achilles, that should be useful for a long time to come.

Finally, for some reason it just decided to start working for me. The MediaDirect button is 255/FF after all...

So there we have it: _IsPressed("FF") controls the MediaDirect button on a dell laptop! Thanks to everyone for bearing with me... Now go tell all of your Inspiron owner friends that their MediaDirect buttons can finally be useful (so long as QuickSet is uninstalled).

One last question, is it possible to use ASCII codes like these with HotKeySet?

Posted (edited)

FreeFry, I just found another script to power off a monitor. It's the current example script on the _SendMessage page in the help file. Here's a copy:

#include <misc.au3>

_Main()

Func _Main()
    Local Const $Off = 2, $On = -1

    Opt("WinTitleMatchMode", 4)
    $hwnd = WinGetHandle('classname=Progman')
    _ToggleMonitor($hWnd, $Off)
    Sleep ( 3000 )
    _ToggleMonitor($hWnd, $On)
EndFunc

Func _ToggleMonitor($hwnd, $OnOff)
    Local Const $WM_SYSCOMMAND = 274
    Local Const $SC_MONITORPOWER = 61808
    _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, $OnOff)
    If @error Then
        MsgBox(0,"_ToggleMonitor", "_SendMessage Error: " & @error)
        Exit
    EndIf
EndFunc
Edited by Xichael
Posted

I'm not sure why it doesn't 'respond' to the Chr(255), a little hard to tell how you're using it..

Btw. here's a a list of keys that can be used with the _IsPressed function: http://msdn2.microsoft.com/en-us/library/m...540(VS.85).aspx

Note that you have to remove the 0x part and it should work.

On a sidenote: I belive if you're trying to use Chr(255) with hotkeyset, I'm not sure that it will work, as it's a 'weird' character...

Posted

FreeFry, I just found another script to power off a monitor. It's the current example script on the _SendMessage page in the help file. Here's a copy:

#include <misc.au3>

_Main()

Func _Main()
    Local Const $Off = 2, $On = -1

    Opt("WinTitleMatchMode", 4)
    $hwnd = WinGetHandle('classname=Progman')
    _ToggleMonitor($hWnd, $Off)
    Sleep ( 3000 )
    _ToggleMonitor($hWnd, $On)
EndFunc

Func _ToggleMonitor($hwnd, $OnOff)
    Local Const $WM_SYSCOMMAND = 274
    Local Const $SC_MONITORPOWER = 61808
    _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, $OnOff)
    If @error Then
        MsgBox(0,"_ToggleMonitor", "_SendMessage Error: " & @error)
        Exit
    EndIf
EndFunc
That's the example I based my script from. :)
Posted (edited)

I'm giving up for now on getting the MediaDirect button to work with a HotKeySet (it seems it just doesn't), and continuing the monitor power off discussion over here.

Thanks everyone...

Edited by Xichael

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
  • Recently Browsing   0 members

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