How to: Block user input temporarily?

A

anders.johansen

Hi,

If I am manipulating text in a word document using e.g. selection
property, I might want to keep the user from inadvertantly typing over
my temporary selection by blocking user input. In Excel I could set
Interactive = false I gather - is there an equivalent setting for
Word?

Sincerely,
Anders
 
J

Jean-Guy Marcil

Hi,

If I am manipulating text in a word document using e.g. selection
property, I might want to keep the user from inadvertantly typing over
my temporary selection by blocking user input. In Excel I could set
Interactive = false I gather - is there an equivalent setting for
Word?

Not sure what you mean.
Why would you need a temporary selection? Can you elaborate, post code
snippets... ?
While the macro is running, the user cannot interact with the document, so
it should no be a problem.

Also, it is better to use the Range object than the Selection one. The Range
object is more reliable, easier to code for and runs faster.
 
A

anders.johansen

Bump.

I am aware that setting ScreenUpdate to false cuts down on the window
of vulnerability, but it does not prevent keyboard input as such.

To make the problem a little more concrete:

I am developing a sort of typo correction, that will at times change
words as the user is writing, kinda like an AutoCorrect on steroids.
This means that, eg. if somebody types ".<space>this<space>" it should
be changed to ".<space>This<space>". However, if the user is typing
"this is", and manages to type the 'i' of 'is' while my program is
changing "this" to "This", the textand/or cursor position may be
screwed up. If I could block keyboard input, at least the user would
only miss out on the 'i'.

Anders
 
J

Jean-Guy Marcil

Bump.

I am aware that setting ScreenUpdate to false cuts down on the window
of vulnerability, but it does not prevent keyboard input as such.

To make the problem a little more concrete:

I am developing a sort of typo correction, that will at times change
words as the user is writing, kinda like an AutoCorrect on steroids.
This means that, eg. if somebody types ".<space>this<space>" it should
be changed to ".<space>This<space>". However, if the user is typing
"this is", and manages to type the 'i' of 'is' while my program is
changing "this" to "This", the textand/or cursor position may be
screwed up. If I could block keyboard input, at least the user would
only miss out on the 'i'.

Hum... it seems to me that your approach needs reviewing. As an regular Word
user I would hate to have some code run and produce unpredictable results
based on my typing speed or some key-combination, and I think I would even
hate it more if the keyboard became locked for a few seconds, or even a half
second... It would mean that some characters I thought I had typed would not
in fact have been typed. I would deactivate that code in no time! But that is
just me...

Seriously though, I do not think you cann lock the keyboard, and even if you
could, I would not recommend it.
From your description, it seems you are creating code that will run all the
time, as long as the user types/works on a document, monitoring input. Code
like that usually hogs way too much resources to make it worthwhile in the
long run. Also, what if the user wants to run another macro?
I think you need another approach, like a button on a toolbar that would
scan the document and fix whatever needs to be fixed. You could go without
the button if you want to automate this by using the BeforeSave event and run
your code then.
 
A

anders.johansen

Hum... it seems to me that your approach needs reviewing. As an regular Word
user I would hate to have some code run and produce unpredictable results
based on my typing speed or some key-combination, and I think I would even
hate it more if the keyboard became locked for a few seconds, or even a half
second... It would mean that some characters I thought I had typed would not
in fact have been typed. I would deactivate that code in no time! But that is
just me...

Of course, you are not dyslexic :)

If you were, you would perhaps really like to have a program running
that would continuously monitor your input, and make suggestions to
fix your spelling errors as well as automatically fixing some common,
easily identifiable typos (non-capped proper names etc.). I know a few
thousand of my users would, as they have tried it and then paid for
it.

A
 
J

Jean-Guy Marcil

Of course, you are not dyslexic :)

If you were, you would perhaps really like to have a program running
that would continuously monitor your input, and make suggestions to
fix your spelling errors as well as automatically fixing some common,
easily identifiable typos (non-capped proper names etc.). I know a few
thousand of my users would, as they have tried it and then paid for
it.

I was not arguing the usefulness of what you are trying to achieve. I was
just commenting on the approach. While your goal maybe praiseworthy, your
approach is fraught with dangers and difficulties that can't easily be cured
with Word VBA. This is why I recommended a few alternatives to help you
achieve your goal.

Even if you manage to make your code run correctly, you will have to warn
your users that as long as your code is running, they cannot use any other
add-ins or macros. Unless, you provide a Stop/Start button that your user
will need to use before and after running code from other macros.
 
F

fumei via OfficeKB.com

I am going to have to agree with Jean-Guy.

"a program running that would continuously monitor your input" is a dangerous
thing for two reasons.

1. it will suck up resources big time

Think about it. "continuously monitor your input" means:

you type " ".....it executes
you type "t".....it executes
you type "h"....it executes
you type "i".... it executes
you type "s"....it executes
you type " ".... it executes
you type "i".....it executes
you type "s".... it executes

and on and on. Word memory management is better than it used to be (the
older ones of us here remember the nightmare of Word 6), but continuously
monitoring input will be a huge strain. As you do not have access to the
REAL guts of Word, you have to work through VBA, which means its parser and
compiler. These take resources.

2. unless your logic is flawless, the possibility of creating typos - rather
than fixing them - is rather high.

I am not disputing the need you express, but I too wonder about the approach.
Real-time monitoring - and possible processing (i.e. changing) - of input in
Word is not recommended. But if you do, be darn sure your logic is bang on.

Jean-Guy Marcil said:
Of course, you are not dyslexic :)
[quoted text clipped - 4 lines]
thousand of my users would, as they have tried it and then paid for
it.

I was not arguing the usefulness of what you are trying to achieve. I was
just commenting on the approach. While your goal maybe praiseworthy, your
approach is fraught with dangers and difficulties that can't easily be cured
with Word VBA. This is why I recommended a few alternatives to help you
achieve your goal.

Even if you manage to make your code run correctly, you will have to warn
your users that as long as your code is running, they cannot use any other
add-ins or macros. Unless, you provide a Stop/Start button that your user
will need to use before and after running code from other macros.
 
A

anders.johansen

I am going to have to agree with Jean-Guy.

"a program running that would continuously monitor your input" is a dangerous
thing for two reasons.

1. it will suck up resources big time

Think about it. "continuously monitor your input" means:

you type " ".....it executes
you type "t".....it executes
you type "h"....it executes
you type "i".... it executes
you type "s"....it executes

<etc>

Yes, I am quite aware of this, but there is no way to program this
except for this way, and having a timer query the state of Word every
now and then.

Yes, it has disadvantages, but if what you want to acchieve is the
program I describe, there is no other way.

No, having the user request the suggestions is not an option.

Yes, the program exists today, has existed for more than five years,
and has thousands of users, so it seems that for a very specific group
of users this provides a necessary service. They not only pay for it
they use it on a daily basis.

I understand your concerns, but they are just not relevant to this
case. The trade-off in question is very different from the one you
describe. These users are willing to put up with the delay and
intrusion, in order to be able to type understandable text at all.

Sincerely,
Anders
 
H

hv

Anders, did you ever find a way to block the input? I need to do the same for one of my scenarios.



Posted as a reply to:

Re: How to: Block user input temporarily?


<etc

Yes, I am quite aware of this, but there is no way to program thi
except for this way, and having a timer query the state of Word ever
now and then

Yes, it has disadvantages, but if what you want to acchieve is th
program I describe, there is no other way

No, having the user request the suggestions is not an option

Yes, the program exists today, has existed for more than five years
and has thousands of users, so it seems that for a very specific grou
of users this provides a necessary service. They not only pay for i
they use it on a daily basis

I understand your concerns, but they are just not relevant to thi
case. The trade-off in question is very different from the one yo
describe. These users are willing to put up with the delay an
intrusion, in order to be able to type understandable text at all

Sincerely
Anders

EggHeadCafe - Software Developer Portal of Choice
WCF Workflow Services Using External Data Exchange
http://www.eggheadcafe.com/tutorial...a-6dafb17b6d74/wcf-workflow-services-usi.aspx
 
D

Doug Robbins - Word MVP

Exactly what is it that you want to do?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
in message news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top