Jump to content

Turn off monitor and block keyboard & mouse


Recommended Posts

I'm trying to writing a script which should function like:

Press a hotkey, monitor is turned off and keyboard/mouse input is blocked (except the hotkey);

Press the hotkey again, monitor is turned on and blocking is removed.

For turning off monitor, I use function like:

Func _Monitor_OFF()
Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
DllCall('user32.dll', 'int', 'SendMessage', _
'hwnd', $Progman_hwnd, _
'int', $WM_SYSCmd, _
'int', $SC_MonitorPower, _
'int', $Power_Off)
EndFunc

and for keyboard & mouse blocking, I tried _BlockInputEx().

However, the keyboard and mouse can be blocked but the monitor cannot stay turned-off when keyboard or mouse is touched. So, any solution?

Link to comment
Share on other sites

Can you please tell us what you need this for? Sounds a bit strange.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

It could be used for when you walk away from your PC you want it to go dark and locked. Seems logical to me.

So why not use Ctrl-Alt-Del or - even faster - Win+L? That's what it was made for, wasn't it?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

So he wants to kill two birds with one stone? Lock the screen and go into power saving mode (darken the screen)?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

Temp00, I can see the monitor bit, and locking the screen if you don't want someone on the PC, but can you please explain why you want to completely block all user input?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Temp00, I can see the monitor bit, and locking the screen if you don't want someone on the PC, but can you please explain why you want to completely block all user input?

Mainly for security, when monitor goes blank, any input except for the unlock hotkey should be deemed as invalid~

Link to comment
Share on other sites

Mainly for security, when monitor goes blank, any input except for the unlock hotkey should be deemed as invalid~

See the quote regarding "Ctrl-Alt-Del".

Autoit is just another program to windows ... it can block all input ... however Ctrl-Alt-Del will still work.

Only the windows OS can lock out a user.

So ... the question is ... why do you want to turn off the monitor?

A locked user shows the login screen only.

Link to comment
Share on other sites

:

As for the monitor, i would use NirCmd, don't know how to do it in autoit,

never tried, Command is: nircmd.exe monitor off

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

See the quote regarding "Ctrl-Alt-Del".

Autoit is just another program to windows ... it can block all input ... however Ctrl-Alt-Del will still work.

Only the windows OS can lock out a user.

So ... the question is ... why do you want to turn off the monitor?

A locked user shows the login screen only.

 

Yes I know that, I believe the fact Ctrl-Alt-Del cannot be blocked is legitimate. I'd like the monitor be turned-off both for energy-saving and for work convenience. I don't like a bright monitor shining in front of me when I read paper work, it's distracting.

Link to comment
Share on other sites

In which case - you do not need a hotkey .... this will do ...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
local $gui = GUICreate("",@DesktopWidth+100,@DesktopHeight+100,Default,Default,$WS_POPUP)
GUISetBkColor(0x000000)
GUISetState()

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Edited by MouseSpotter
Link to comment
Share on other sites

Did you post this code in autoitcode? Because when i copy paste this, it will be a very long string, and the line feeds are not copied.

EDIT: btw theres a missing endif

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

 

EDIT: btw theres a missing endif

There's no missing EndIf in that code, it's a single line If...Then statement which doesn't require, and can't use, an Endif statement.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Did you post this code in autoitcode? Because when i copy paste this, it will be a very long string, and the line feeds are not copied.

EDIT: btw theres a missing endif

The copy&paste missed the end bracket in the last line "GUIDelete(" ... which I have now fixed.

The code copies & pastes from the webpage fine for me.

I used the AutoIt code type from the forum editor "code" icon.

Link to comment
Share on other sites

sounds phishy... like creating a temporary bug or more of a virus/hi-jack creation. If it doesn't accept user input; how will you turn the pc on to the stage where you can input user password?

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

 

In which case - you do not need a hotkey .... this will do ...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
local $gui = GUICreate("",@DesktopWidth+100,@DesktopHeight+100,Default,Default,$WS_POPUP)
GUISetBkColor(0x000000)
GUISetState()

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

 

Ah...we can call this a work-around, though not pretty

Link to comment
Share on other sites

sounds phishy... like creating a temporary bug or more of a virus/hi-jack creation. If it doesn't accept user input; how will you turn the pc on to the stage where you can input user password?

 

What do you mean by "phishy"? I think you should read my first post again~ A hotkey is excluded from blocking for toggle the monitor/keyboard&mouse

Link to comment
Share on other sites

  • Moderators

sounds phishy... like creating a temporary bug or more of a virus/hi-jack creation. If it doesn't accept user input; how will you turn the pc on to the stage where you can input user password?

 

After your thread yesterday, where you refused to give the title of the window you were trying to manipulate, should you really be casting doubt on anyone else's post? ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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...