Tags: apps, calls, disable, emulators, excel, keyboard, microsoft, mouse, msdn, non-windows, programs, routine, running, software, terminal, vba

disable keyboard/mouse from vba for all programs?

On Microsoft » Microsoft Excel

4,334 words with 3 Comments; publish: Fri, 23 May 2008 09:03:00 GMT; (306265.63, « »)

I am running a routine from excel vba that calls some other non excel

apps, some are non-windows ones in terminal emulators, and if anyone

does any keystrokes etc while the whole thing is running it really

messes up. I've found some things which will disable the keyboard

just for the excel/vba app, but this is not enough as focus passes to

the other programs for a while, and i need to keep the keyboard turned

off while this is the case. I realise that this could be a dangerous

thing to do so don't want to mess with registry stuff, just do it in

VBA so that if something does go wrong i can always hit the power

plug. Something that looked like

Sub Main()

Keyboard.disable

call first-app

call next sub

shell another.bat

keyboard.enable (or keyboard.disable = false)

end sub

any suggestions please?

All Comments

Leave a comment...

  • 3 Comments
    • Hi,

      shell("mode con=off") to disable keyboard.

      shell("mode con=on") to enable.

      If your code crashes a hard reboot will be required. No keyboard, no

      ctl-alt-del.

      No idea on the mouse.

      --

      John

      johnf202 at hotmail dot com

      "kk" <kkkbeetle.excel.todaysummary.com.yahoo.com> wrote in message

      news:94cf2709.0310160058.45739c7.excel.todaysummary.com.posting.google.com...

      > I am running a routine from excel vba that calls some other non excel

      > apps, some are non-windows ones in terminal emulators, and if anyone

      > does any keystrokes etc while the whole thing is running it really

      > messes up. I've found some things which will disable the keyboard

      > just for the excel/vba app, but this is not enough as focus passes to

      > the other programs for a while, and i need to keep the keyboard turned

      > off while this is the case. I realise that this could be a dangerous

      > thing to do so don't want to mess with registry stuff, just do it in

      > VBA so that if something does go wrong i can always hit the power

      > plug. Something that looked like

      > Sub Main()

      > Keyboard.disable

      > call first-app

      > call next sub

      > shell another.bat

      > keyboard.enable (or keyboard.disable = false)

      > end sub

      > any suggestions please?

      #1; Fri, 23 May 2008 09:04:00 GMT
    • "jaf" <me.excel.todaysummary.com.here.com> wrote in message news:<OT0YeB#kDHA.1084.excel.todaysummary.com.tk2msftngp13.phx.gbl>...

      > Hi,

      > shell("mode con=off") to disable keyboard.

      > shell("mode con=on") to enable.

      > If your code crashes a hard reboot will be required. No keyboard, no

      > ctl-alt-del.

      > No idea on the mouse.

      >

      Thanks, but it doesn't work, i get error message "run time error 53;

      file not found", and it stops at that line.

      regards

      #2; Fri, 23 May 2008 09:05:00 GMT
    • Hi,

      Sorry, the old DOS trick doesn't work anymore.

      I found two other methods. The first uses API's.

      Declare Function BlockInput Lib "USER32.dll" (ByVal fBlockIt As Long) As

      Long

      Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

      Sub test() 'both keyboard and mouse blocked

      BlockInput True 'off

      ' call sub:

      'optional: Sleep 5000

      BlockInput False 'on

      End Sub

      And the second from an MS Article mentioning Excel specifically. I haven't

      test it so I don't know about other apps running.

      ' Macro to turn off keyboard entry.

      Sub KeyboardOff()

      ' Sets CTRL+D to activate KeyboardOn.

      Application.OnKey "^d", "KeyboardOn"

      Application.DataEntryMode = True

      End Sub

      ' Macro to restore keyboard entry.

      Sub KeyboardOn()

      Application.DataEntryMode = False

      End Sub

      --

      John

      johnf202 at hotmail dot com

      "kk" <kkkbeetle.excel.todaysummary.com.yahoo.com> wrote in message

      news:94cf2709.0310170659.6e7bfb6d.excel.todaysummary.com.posting.google.com...

      > "jaf" <me.excel.todaysummary.com.here.com> wrote in message

      news:<OT0YeB#kDHA.1084.excel.todaysummary.com.tk2msftngp13.phx.gbl>...

      > > Hi,

      > > shell("mode con=off") to disable keyboard.

      > > shell("mode con=on") to enable.

      > >

      > > If your code crashes a hard reboot will be required. No keyboard, no

      > > ctl-alt-del.

      > >

      > > No idea on the mouse.

      > >

      > Thanks, but it doesn't work, i get error message "run time error 53;

      > file not found", and it stops at that line.

      > regards

      #3; Fri, 23 May 2008 09:06:00 GMT