FreeFry Posted February 25, 2008 Posted February 25, 2008 (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 EndFuncEdit: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 February 25, 2008 by FreeFry
Xichael Posted February 25, 2008 Author Posted February 25, 2008 (edited) see this #450718Sorry 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 February 25, 2008 by Xichael
FreeFry Posted February 25, 2008 Posted February 25, 2008 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).
Xichael Posted February 25, 2008 Author Posted February 25, 2008 (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 February 25, 2008 by Xichael
Achilles Posted February 25, 2008 Posted February 25, 2008 Run this: expandcollapse popupGlobal 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 ;==>OnAutoItExitAnd 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]
Xichael Posted February 25, 2008 Author Posted February 25, 2008 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?
Achilles Posted February 25, 2008 Posted February 25, 2008 For most of the keys you could just use a Chr call to change it... like this: Msgbox(0, '65 = A', Chr(65))Or HotKeySet(Chr(65), '_Func') My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Xichael Posted February 25, 2008 Author Posted February 25, 2008 (edited) Is there any benefit to using one over the other? Edited February 25, 2008 by Xichael
Xichael Posted February 25, 2008 Author Posted February 25, 2008 (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 February 25, 2008 by Xichael
Achilles Posted February 25, 2008 Posted February 25, 2008 Is there any benefit to using one over the other?HotKeySet is probably more efficient since it doesn't have to be constantly checked. _IsPressed() sends the key by default, but HotKeySet can be changed to send the key that is pressed... So basically I prefer Hotkeyset a lot more then _IsPressed... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Xichael Posted February 25, 2008 Author Posted February 25, 2008 (edited) Chr(255) isn't responding to the MediaDirect button as it should... Why would that be? Edited February 25, 2008 by Xichael
FreeFry Posted February 25, 2008 Posted February 25, 2008 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).aspxNote 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...
FreeFry Posted February 25, 2008 Posted February 25, 2008 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 EndFuncThat's the example I based my script from.
Xichael Posted February 26, 2008 Author Posted February 26, 2008 (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 February 26, 2008 by Xichael
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now