Temporarily Disable Keyboard and Mouse input During a Macro

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Temporarily Disable Keyboard and Mouse input During a Macro

Post by HPROS » Tue Oct 28, 2003 3:46 pm

I would like to formally submit this request for a future release/enhancement. It would be great to be able to disable keyboard and mouse input at the beginning of a macro/script so that the macro/script can run safely uninterrupted by the end-user. Once the macro/script finishes you would re-enable the keyboard and mouse within the macro as it finishes. MacroScheduler is a great tool, however it loses value if it can only be run after hours, or on a separate workstation, because if you run it on an actively used workstation and a macro starts up, the user can easily blow it out of the water with keyboard or mouse input while it runs. I have seen attempts using Rundll32.exe or Rundll.exe (without rebooting) to do this, however nothing that worked on my XP machine. I would want it to work on all Windows platforms to have real value. I know it can be done, as a number of applications employ this, for example PcAnyware takes over a workstation remotely and sends keyboard and mouse commands to the remote machine, AND it can also prohibit remote keyboard input for the SAME reasons that I mentioned, and then once the session ends, keyboard and mouse input are restored on the remote workstation without needing a reboot.

Thank you for your consideration. :D
Last edited by HPROS on Wed Oct 29, 2003 12:56 am, edited 1 time in total.

Lumumba

Post by Lumumba » Tue Oct 28, 2003 4:51 pm

a) I agree. There a few (nervous) people around who can't wait till an installation has been finished. Often caused by missing messages/progress bars etc. to show that the system is still busy.

b) I definitely won't agree - for security reason. I don't want you to act on my box (without the option to stop you for whatever reason).
If I would start a virus/trojan implementation instead of a boring standard setup routine on your box, would you be happy to have no options (beside to plug it of)?

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Tue Oct 28, 2003 5:08 pm

Thank you for your comments. You may still be able to have a hot-key out i.e. shift-esc to break in. The objective is to control standard keyboard and mouse input that will send a macro awry. In fact the way I would employ it would be to minimize all windows, display a message that explains the macros objective and estimated completion time, and perhaps the "emergency hot-key" exit (shift-esc or whatever it is), and then I would immediately disable the mouse and keyboard leaving the message on the screen. Once the macro completes, enable all input and remove the message. - Thanks

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Fri Oct 31, 2003 3:09 pm

I have been trying different avenues to solve this issue, and I may be close. Here is sytanx that I am told should work inserted into my macros, however I get errors. Can anyone try this out and work through the VBscrpiting syntax to get this working? - Thanks!

Private Declare Function BlockInput Lib "user32" ( ByVal fBlock As Boolean) As Boolean

When the macro begins, add
sub somemacro()
blockinput = true
...
this will stop input.

At the end insert
....
blockinput = false.
End Sub

This will allow control again.

Also in there add error checking controls so that if the macro exits early, it sets blockinput = false.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Oct 31, 2003 4:59 pm

:idea: I have located a working demo script to block input. The code is at this site:
http://home.att.net/~geekStuff/wshBlockInputPage.htm
JWarrington has provided two ActiveX controls and the vbs file to do this. Takes about two minutes to install and run.

Need to register two ocx files in C:\windows\system using Run, RegSvr32 fullpath\filename.ocx

:D The following line works good as a demo.on my system:
Execute>Q:\Masters\New\Scripts\wshBlockInputDemo.vbs
=======================================
Just some random notes about using this right now:
1. Need to modify internals of script for personal use. I have not had a chance to really look at that yet.
2. Perhaps modify this script to call Macro Scheduler vs. putting this command into Macro Scheduler. I think that will be the final process if this is used.
3. Downside is that ocx files are needed which makes it difficult to deploy on other systems. But simple enough to do with commands as long as the ocx files are included as part of the installation package. Put the ocx files and the Macro Scheduler script into a zip file and extract to same folder. Have a Macro Scheduler script copy the files and do the registration if needed.
==========================================
Original vbs code unreviewed by me.
Original vbs from JWarrington included here for reference:
' wshBlockInput.vbs, jw 19Oct01
'
' --- description block --------------------------
'
' Title: wsh Block Input Demo Script
'
' Description: wshBI provides a means of blocking
' all keyboard and mouse activity,
' while your script is running...
'
' Author: jwarrington*NoSteekinSpam*@worldnet.att.net
' Website: http://home.att.net/~wshvbs/index.htm
'
' Usage: Use at you own risk, tested on win98se...
'
' --- revision history ---------------------------
' 19Oct01: original attempt...
' --- end of description block -------------------

Option Explicit
'
' instantiate ActX components here...
' (note: using "call instantiate" to provide better info in case obj is missing)
Dim oNMD : Call Instantiate (oNMD, "wshLtWtNonModalDialog.ucNMD", "oNMD_")
Dim oATO : Call Instantiate (oATO, "wshAPIToolkitObject.ucATO", "") ' (no events)
'
'
Dim m_btnExitID ' as integer
'
Dim bCloseFlag ' t/f if user closed the form...
Dim bExitClick ' as boolean
'
Dim mnuArray ' as variant (array of menu items)
Dim sEvent ' as string
'
Const sIconPath = "c:\windows\wscript.exe" ' path to desired icon
Const sIconNr = "0" ' ordinal of icon in the above dll, exe...
'
Dim nRtn ' as long
Const m_sCaption = " > "
Const m_sLogo = "brought to you by: jawar productions. (clap, clap, clap)... "
Dim oForm ' oNMD's "form object"
Dim m_hForm
' --- end of declarations and constants ----------


' ================================================
' === MAIN LINE SCRIPT LOGIC =====================
' ================================================

' Create the Form, and add the controls...
Call Create_Form()

Set oForm = oNMD.frmDialog ' getref to form object
m_hForm = oForm.hWnd ' get form handle
' oNMD.AddLine "Form Created. (form hWnd is: " & Hex(m_hForm)

' make adjustments to form objects...
oForm.ImageBox(1).Picture = LoadPicture(GetLocalDirectory & "Dilbert.ico")
oForm.Label(2).ForeColor = vbRed
oForm.Label(3).ForeColor = vbRed
oForm.Button(1).Visible = False
With oForm.Label(5).Font
.Name = "Arial" : .Size = 7 : .Bold = False : .Italic = True
End With

oNMD.EnableCloseBtn = False ' DIS-able the close button...

Call BlockInput(True) ' block any keybd or mouse input...

oNMD.ShowDialog True ' show the form (er, dialog)...

' wait around for user cancel/close...
bCloseFlag = FALSE ' set close flag as undetected.
bExitClick = False

Dim iPctDone
For iPctDone = 1 to 100
WScript.Sleep 200 ' wait/delay (pretend script is working)...
' with BlockInput in effect, text whether any clicks getting through...
if bExitClick then Exit For
if bCloseFlag then Exit For

oNMD.PctComplete iPctDone ' advance progbar

Next ' end of "for" loop...

' finished with the script business, let the user know...
With oForm.Label(2)
.Visible = False
.Caption = "The Script is Finished. " _
& "Your Group Collaboration Software has been installed successfully. "
.Font.Size = 12 : .ForeColor = vbGreen : .Visible = True
End With
With oForm.Label(3)
.Visible = False
.Caption = "We do appreciate your patience... "
.Font.Size = 12 : .ForeColor = vbGreen : .Visible = True
End With

oNMD.EnableCloseBtn = True ' EN-able the close button...
oForm.Button(1).Visible = True

Call BlockInput(False) ' UN-BlockInput

Do
WScript.Sleep 200 ' allow for processing events...

Loop Until (bExitClick Or bCloseFlag)

Set oForm = nothing
Set oNMD = nothing ' clean up
Set oATO = nothing
WScript.Quit

' ================================================
' === SUBROUTINES FOLLOW =========================
' ================================================



' --- click event handlers ---
Sub oNMD_ButtonClick(btnID)
' MsgBox("Button Clicked, ID = " & CStr(btnID))
if btnID = m_btnExitID then bExitClick = True
End Sub

Sub oNMD_UserClose()
' MsgBox(" .. user close detected")
bCloseFlag = TRUE
End Sub



' --- this code creates the form and adds the controls ---

Sub Create_Form()
Dim wdForm, htForm, wdBtn, htBtn, wdBtnSp ' as long

' do some geometry calculations...
wdForm = 460 : htForm = 320 : wdBtn = 150 : htBtn = 25
wdBtnSp = Int((wdForm - wdBtn) / 2) - 3

oNMD.CreateDialog m_sCaption, 40,40, CLng(wdForm),CLng(htForm) ' top was 100

oNMD.AddImageBox 20,15, 32,32
oNMD.AddLabel "Hi. I'm Reginald, your over-worked (but still helpful and friendly) " _
& "SysAdmin. Today, I'm going to be installing some new Group Collaboration " _
& "Software for you. ", 70,15, 400,45


' ==============================================
' === Draw an "Etched Edge" separator ==========

' draw a home-made "etched edge" line, using vbRect and accent line,
' (Note: you started with white, but then "softened" it a bit)...
Const topSep = 65
Const vbFSSolid = 0 ' fill style constant
Const crOffWhite = &HF0F0F0
Const crDkGray = &H808080
With oNMD.frmDialog
.AutoRedraw = True ' set autoredraw (so as to "persist" the vb graphics)...
.FillColor = vbWhite ' crOffWhite ' start with white box (ht = 2pix)
.FillStyle = vbFSSolid
.vbRectangle 20,topSep, wdForm-45,2, vbWhite ' crOffWhite
.vbLine 20+1,topSep, wdForm-45-2,0, crDkGray ' vbBlack ' black accent line
End With

oNMD.AddLabel "Nota Bene: It's VERY IMPORTANT not to disturb this script while it's " _
& "running. Any interruptions could mess up this software installation, " _
& "resulting in an inoperable system. That would be extremely unfortunate " _
& "for both you and me. (Especially for me). ", 20,topSep+10, wdForm-45,60

oNMD.AddLabel "To prevent any interruptions, I have locked the keyboard and mouse " _
& "temporarily, so you can't use the system. Kindly take a short break, " _
& "enjoy a cup of coffee or a diet coke (courtesy of the IT department). " _
& "Your system will be ready to go in about two minutes... ", _
20,topSep+70, wdForm-45,60


' === Draw an "Etched Edge" separator ==========
With oNMD.frmDialog
.vbRectangle 20,topSep+130, wdForm-45,2, vbWhite ' crOffWhite
.vbLine 20+1,topSep+130, wdForm-45-2,0, crDkGray ' vbBlack ' black accent line
End With

Const htCaption = 25
Dim htClient : htClient = htForm - htCaption

oNMD.AddLabel "Script Progress Bar... ", 45,htClient-20-htBtn-25-20, 360,15


oNMD.AddProgressBar 40,htClient-20-htBtn-25, 360,20

oNMD.AddButton "Close This Dialog", wdBtnSp,htClient-15-htBtn, wdBtn,htBtn
m_btnExitID = 101 ' the first button created has an ID of 101

oNMD.AddLabel m_sLogo, 180,htClient-12, 400,15
' --- finished with creating the form ---

End Sub


' --- ADD ADVISORY EXIT MESSAGES TO THE LSTBOX ---

Sub ExitMsg (bExit, bClose)

oNMD.AddLine " " ' space down one line...

if bExit then ' test for exit/close click...
oNMD.AddLine " => User Clicked Exit, "
elseif bClose then
oNMD.AddLine " => User Clicked Close [X] Button, "
End If

oNMD.AddLine " (this window will close in 2 secs)... "
WScript.Sleep 2000
End Sub


' ================================================
' ================================================
' === "WRAPPERS" FOR API CALLS ===================
' ================================================
' ================================================

Function BlockInput(bFlag)
BlockInput = oATO.CallAPI("USER32.DLL", "BlockInput", bFlag)
End Function



' ------------------------------------------------
' --- Get Local Directory (of this script) -------
' ------------------------------------------------

' Note: when fso is instantiated, then use this:
' GetLocalDirectory = fso.GetFile(WScript.ScriptFullName).ParentFolder
'
' (however, if fso NOT instantiated, use the following code,
' it's more efficient there are NO additional ole instantiations
' required, with all that ugly and slow "late-binding")...
'
' --- other possibilities from the wsh ng, (mikHar)...
' --- wsh 5.5 ---
' set fso = createobject("scripting.filesystemobject")
' currentDirectory = fso.getabsolutepathname(".")
' --- wsh 5.6 ---
' set shell = createobject("wscript.shell")
' currentDirectory = shell.currentdirectory
' --- end of other possibilities -----------------
'
Function GetLocalDirectory()
Const sMe = "[GetLocalDirectory], "
Dim iFile ' as integer

' find the LAST backslash...

iFile = InStrRev(Wscript.ScriptFullName, "\")
BugAssert (iFile > 0), sMe & " file path problem " ' if backslash not found...

' get the path to this script...
GetLocalDirectory = Left(Wscript.ScriptFullName, iFile) ' path (inc "\")...

End Function



' ================================================
' === INSTANTIATE ACTX OBJ and BUGASSERT =========
' ================================================


' --- INSTANTIATE ACTX OBJECT (or class) AND CHECK ----
' (using a sub to get this ugly instantiation code out of main line code)...

Sub Instantiate (oObject, sProgramID, sEventPrefix)
Const sME = "[sub Instantiate], "
' check variant sub-type parameters...
BugAssert (VarType(sProgramID) = vbString), sME & "sProgramID must be a STRING!"
BugAssert (VarType(sEventPrefix) = vbString), sME & "sEventPrefix must be a STRING!"
On Error Resume Next ' turn on error checking
Set oObject = WScript.CreateObject(sProgramID, sEventPrefix)
BugAssert (err.number = 0), sME & "This script requires: " & sProgramID & vbCrlf _
& " kindly INSTALL and REGISTER this ActX component... "
On Error goto 0 ' turn off error checking...
End Sub


' --- BUGASSERT (yes, it's for debugging) --------

Sub BugAssert (bTest, sErrMsg)
Dim sDblSpace : sDblSpace = vbCrLf & vbCrLf

' BugAssert is a Bruce McKinney creation.
' It is used to test for intermediate results...

if bTest then Exit Sub ' normally (hopefully) test returns true...

MsgBox "Error Message reported by BugAssert: " & sDblSpace _
& sErrMsg & sDblSpace & " this script will terminate NOW. ", _
vbCritical, " > "
WScript.Quit

End Sub

Sub Old_Code()


End Sub
=========================================
For HPROS: Since you are working on this independently, perhaps a review of this code will be of help to you? Possibly use the vb section that is doing the blocking, and forget about the screens? Then can have Macro Scheduler call vb code as part of MS script vs. my thoughts above with this script calling MS.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Mon Nov 03, 2003 12:31 pm

Bad news! I pulled down the code that Bob mentioned above and modified it to create two utilities, a Block.vbs and an Unblock.vbs. That part worked like a charm, however when I put it all together and tested it I found that when the mouse and keyboard input is blocked by the script so were any keystrokes that Macro Scheduler sent via my scripts. All other elements of my scripts worked, however any "Send Charachter/Text>" was also blocked (bummer)! I was hoping that it would act more like PcAnyware in that it blocked local keyboard and mouse activity, but allowed remote keyboard and mouse activity (in this case via a script).

Special "Thanks" to Bob for his efforts!

I will keep looking...

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Nov 04, 2003 12:10 am

Arrrgh! Your explanation really makes sense. :cry:

:idea: OK, guess we need to do a hack on pcAnyWhere and find out their method. But I suspect it is going to be something like enabling certain ports thac can be done because remote input is using different i/o ports. So,could be redirect the Macro Scheduler inputs through a different port also? (Suggesting things I know nothing about, just doing some free-thinking here).

Would you mind providing the two vbs functions that you came up with? i have also been modifying that script (very few spare moments), and would be curious to see how you did it.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Tue Nov 04, 2003 11:59 am

I was thinking about it, and I think PcAnyware may use the Telenet Keyboard and Mouse to send the mouse movement and keystrokes rather than the standard microsoft PS2 mouse and keyboard. I think there are different drivers and/or handlers for those that the Microsoft "Blockinput" command does not block.

Thoughts...? :?

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Tue Nov 04, 2003 12:23 pm

Regarding the modifications to the vbs code above, I just made two copies of the original script a "block" and an "unblock". Then in the Block I remarked out the "Call BlockInput(False)" so that it stays blocked. My macro begins by executing the "block" vbs and then goes right into my macro where it works on everything but keyboard input from Macro Scheduler (I stay away from mouse but it blocked that too). At the end of the macro I execute the unblock vbs script that had the "Call BlockInput(False)" in it to unblock the input again. You can cut out at any point with a ctrl-alt-del which is nice. Had it worked, I was going to pretty things up and cut out all unnecessary code and edit the dialog box to describe the macro and the estimated completion time etc...

- Thanks :(

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts