switch off keyboard and mouse input

Chris Davison

MrExcel MVP
Joined
Feb 15, 2002
Messages
1,790
Morning all and Merry Xmas,

some of my stupid clients insist on still trying to type and mouseclick whilst a macro is running that uses SENDKEYS and MOUSECLICK input..... obviously, this messes up the macro and it goes in the wrong direction or crashes

is it possible to disable any manual keyboard input and mouse clicking input at the beginning of the macro and switch them back on at the end of the macro so they can't do this ?

many thanks
Chris
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

CDICKENS

Active Member
Joined
Mar 24, 2002
Messages
498
This API function will hide the mouse Cursor...

Code:
Declare Function ShowCursor& Lib "user32" (ByVal bShow As Long)
 
'Hide mouse cursor
Call ShowCursor&(0)
 
'Show mouse cursor
Call ShowCursor&(1)

Caveat! This hides the cursor from ALL open applications.

What are you using sendkeys for?

SendMessage API may be a better alternative.

Chuck[/url]
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
Public inputMsg As String
Sub BlockInPut()
'Stop input for mouse only on message!

'Turn off number pads ENTER key.
Application.OnKey "{ENTER}", "myMsg"

'Turn off regular ENTER key.
Application.OnKey "~", "myMsg"

'Turn off all character keys.
Application.Interactive = False

'GoTo myMsg Sub.
myMsg
End Sub

Sub myMsg()
Dim Note
'Display Message box.
inputMsg = "Your Keyboard Input has been Stopped! Please use you Mouse to Respond!"
Note = MsgBox(inputMsg, vbOKCancel + vbDefaultButton2 + vbCritical, "Your Stopped!")
If Note = vbCancel Then
BlockInPut
End If
'GoTo RestoreInPut Sub.
RestoreInPut
End Sub

Sub RestoreInPut()
'Turn on all keys!
Application.Interactive = True
Application.OnKey "{ENTER}"
Application.OnKey "~"
End Sub

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
RestoreInPut
End Sub



Then code like this:


Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
'ThisWorkbook module code!

If Sh.Name = "Sheet2" Then
Cancel = True
End If

End Sub


Will stop the mouse Right-Click on Sheet2!
 

Watch MrExcel Video

Forum statistics

Threads
1,119,128
Messages
5,576,261
Members
412,709
Latest member
Rishu
Top