Connecting Tech Pros Worldwide Forums | Help | Site Map

disable mouse and keyboard

Alireza355's Avatar
Member
 
Join Date: Feb 2009
Location: Iran
Posts: 68
#1: Jun 8 '09
Dear friends,

I have a command button that when clicked, runs tens of queries, millions of calculations, etc.

This process takes about 10 seconds each time, and the mouse pointer rapidly changes into hourglass and changes back to pointer during this process.

If the user opens other forms or does other things while the main calculations are not finished yet, the results would be disaster. So I want to disarm the user by disabling mouse and keyboard before starting calculations, and re-enable them after finishing the calculations.


Possible???????????????

Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,253
#2: Jun 8 '09

re: disable mouse and keyboard


Making the form with the command button Modal would prevent other windows from being opened. Just disable other controls on that one form until the operations are complete.
Alireza355's Avatar
Member
 
Join Date: Feb 2009
Location: Iran
Posts: 68
#3: Jun 8 '09

re: disable mouse and keyboard


some of the calculations are done after the form is closed, and no form is open.

I need a more """""""reliable"""""""" way!!!!
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,253
#4: Jun 8 '09

re: disable mouse and keyboard


Why do you close the form if you don't want the user doing anything? Just display a message saying Please Wait, or a progress bar, or something.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 16,173
#5: Jun 8 '09

re: disable mouse and keyboard


Keep the form open (invisible if you prefer) and handle any events that may fire.

In essense, the code that has already been invoked should run through without interruption anyway.

Keyboard and mouse events should be queued to run later if code is already executing.
Site Addict
 
Join Date: Mar 2007
Location: Oakland, California, USA
Posts: 528
#6: Jun 8 '09

re: disable mouse and keyboard


Quote:
So I want to disarm the user by disabling mouse and keyboard before starting calculations, and re-enable them after finishing the calculations
I wouldn't think this is a good idea. User could not do something else, like check email. Also, if something goes wrong, computer is effectively locked, and must be rebooted, causing loss in any other open programs.

Quote:
I have a command button that when clicked, runs tens of queries, millions of calculations, etc.
This sounds as if the results of calculations are stored in tables, and not re-calculated 'on-the-fly'. Without more information, we don't know if this is appropriate.

If this button opened a New Form as modal, this new form could have a status bar and/or "Please Wait". It might also have a "Cancel" button if cancelling is possible. This form would be closed on completion. This would allow the user to change programs, but not continue to work in the current program while the
Quote:
tens of queries, millions of calculations
are being executed.

Warning, if another Access program uses the same tables, they would still be accessable to the user with any of the proposed solutions in this thread. The issues raised in the original post will then need to be addressed.
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,429
#7: Jun 8 '09

re: disable mouse and keyboard


Quote:

Originally Posted by Alireza355 View Post

Dear friends,

I have a command button that when clicked, runs tens of queries, millions of calculations, etc.

This process takes about 10 seconds each time, and the mouse pointer rapidly changes into hourglass and changes back to pointer during this process.

If the user opens other forms or does other things while the main calculations are not finished yet, the results would be disaster. So I want to disarm the user by disabling mouse and keyboard before starting calculations, and re-enable them after finishing the calculations.


Possible???????????????

Very possible. I know that I will probably raise a few eyebrows on this one, but I can actually see the need to Block Keyboard and Mouse Input during intensive operations in order to maintain a sort of System Modality. This is only acceptable, at least to me, if there is some kind of visual cue for the User indicating this Inactive Input State, in this case the 'Olde Hourglass'. In any event, here it goes:
  • Declare the following API Function:
    Expand|Select|Wrap|Line Numbers
    1. Public Declare Function BlockInput Lib "USER32.dll" (ByVal fBlockIt As Long) As Long
  • Write Code 'similar to' the following. I would strongly assume writing the Code within the context of an Error Trap to Unblock Input and also to turn the Hourglass OFF shound an Error occur:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub ImpData_Click()
    2. On Error GoTo Err_ImpData_Click
    3. Dim intCounter As Long
    4.  
    5. DoCmd.Hourglass True
    6.  
    7. BlockInput True
    8.  
    9. For intCounter = 1 To 2147000000
    10.   'take a nap!
    11. Next
    12.  
    13. BlockInput False
    14.  
    15. DoCmd.Hourglass False
    16.  
    17. Exit_ImpData_Click:
    18.   Exit Sub
    19.  
    20. Err_ImpData_Click:
    21.   BlockInput False: DoCmd.Hourglass False
    22.     MsgBox Err.Description, vbExclamation, "Error in Pic Names"
    23.     Resume Exit_ImpData_Click
    24. End Sub
  • BTW, there is an Escape Route, ALT + CTRL + DEL will effectively Disable Input Blocking.
  • Good Luck, and let us know how you make out should you attempt this controversial approach.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 16,173
#8: Jun 8 '09

re: disable mouse and keyboard


Quote:

Originally Posted by ADezii View Post

Very possible. ...

I just should'a known you'd 'a known :D

We won't talk about the potential for dodginess here. I'm just impressed you would know such an apposite answer.
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,429
#9: Jun 8 '09

re: disable mouse and keyboard


Quote:

Originally Posted by NeoPa View Post

I just should'a known you'd 'a known :D

We won't talk about the potential for dodginess here. I'm just impressed you would know such an apposite answer.

I also knew that the 1st eyebrow to be raised would be yours (LOL)!
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 16,173
#10: Jun 8 '09

re: disable mouse and keyboard


My judgement was that it was definitely worth posting. Eyebrows firmly settled ;)
FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#11: Jun 8 '09

re: disable mouse and keyboard


MSDN: BlockInput()

Oh, yeah. Hangs as good as possible.
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,429
#12: Jun 8 '09

re: disable mouse and keyboard


Quote:

Originally Posted by NeoPa View Post

My judgement was that it was definitely worth posting. Eyebrows firmly settled ;)

BTW, what Degree of dodginess am I (1, 2, or 3)?

dodg·y (dj)
adj. dodg·i·er, dodg·i·est Chiefly British
  1. Evasive; shifty.
  2. Unsound, unstable, and unreliable.
  3. So risky as to require very deft handling
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 16,173
#13: Jun 9 '09

re: disable mouse and keyboard


Not you ADezii.

The potential is for the information you make available to be misused.

Obviously, you're well dodgy, but that's not the point :D
Alireza355's Avatar
Member
 
Join Date: Feb 2009
Location: Iran
Posts: 68
#14: Jun 9 '09

re: disable mouse and keyboard


Thank you all, specially ADezii

Thank you so much.
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,429
#15: Jun 9 '09

re: disable mouse and keyboard


Quote:

Originally Posted by Alireza355 View Post

Thank you all, specially ADezii

Thank you so much.

You are quite welcome. Be careful in the use of this code, and 'always' provide a mechanism for enabling Keyboard/Mouse Input once again should an Error occur midstream. Good Luck, and let us know how it all works out.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 16,173
#16: Jun 9 '09

re: disable mouse and keyboard


That's always good advice ADezii, but from Fish's link it will recover itself on any unhandled crash and a Ctrl-Alt_Del always gives any operator the power to cancel this effect. This even reduces the dodginess factor :D
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,429
#17: Jun 10 '09

re: disable mouse and keyboard


Quote:

Originally Posted by NeoPa View Post

That's always good advice ADezii, but from Fish's link it will recover itself on any unhandled crash and a Ctrl-Alt_Del always gives any operator the power to cancel this effect. This even reduces the dodginess factor :D

Quote:
This even reduces the dodginess factor
Does that mean that the code has been Dedoged? (LOL)
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 16,173
#18: Jun 10 '09

re: disable mouse and keyboard


Entirely? No. Predominantly though? Yes.

PS. Just because you see there are so many 'D's in the word is no excuse to leave one out. Is four 'D's too much for a single word? Probably yes.

Still should be De-dodged :D
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,429
#19: Jun 11 '09

re: disable mouse and keyboard


Quote:

Originally Posted by NeoPa View Post

Entirely? No. Predominantly though? Yes.

PS. Just because you see there are so many 'D's in the word is no excuse to leave one out. Is four 'D's too much for a single word? Probably yes.

Still should be De-dodged :D

I stand corrected-ed! (LOL)!
Reply