Capture ALL movements...event?

B

Brenda

Currently I am trying to create my own StatusBar because the Word StatusBar
doesn't display when you are using it with Internet Explorer. My question is
what event do you use to capture every movement of the cursor(pointer) so I
can display the current line, section, column, etc...? I've tried
Me.SelectionChange but it only captures some of the movements. It doesn't
capture when I hit the Enter button, etc...

Any ideas? Thanks for your time!
 
J

Jonathan West

Brenda said:
Currently I am trying to create my own StatusBar because the Word
StatusBar
doesn't display when you are using it with Internet Explorer. My question
is
what event do you use to capture every movement of the cursor(pointer) so
I
can display the current line, section, column, etc...? I've tried
Me.SelectionChange but it only captures some of the movements. It doesn't
capture when I hit the Enter button, etc...

Any ideas? Thanks for your time!

The closest I think you can get to this is the WindowSelectionChange event.
The following article shows you how to write event procedures for
application-level events

Writing application event procedures
http://www.word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
T

Tony Jollans

No. There just simply isn't an event which fires off every keystroke.

It might, theoretically, be possible to assign every keystroke to a macro
and perform some appropriate action, but it would be extremely difficult to
write and a hell of a perfomance hit and would probably still fail in some
cases (field updates, for example). Alternatively some low level APIs might
get you there.

For sure this won't be easy even if it's possible. Is the status bar that
important to you?
 
B

Brenda

To me, I could care less about the status bar, but my boss is admit about
having it display for our users. Ideally, I wish it would work in IE. I
guess I'll just have to deal with the WindowSelectionChange the best I can.

Thanks!
 
J

Jezebel

It is technically possible to do through API calls, to monitor the message
queue, which receives *every* mouse and keyboard event. But it's a
truck-load of work, and unlikely to deliver a useful outcome. The
WindowSelectionChange event isn't very satisfactory -- some selection
changes initiated entirely from the keyboard are missed, and it has trouble
with application switching. It's also a debugging nightmare, because
switching between the app and VBA also fires the event.
 
T

Tony Jollans

Apart from the dynamic position data, there are the toggles (OVR, TRK, etc)
which will be even harder to mimic.

Tell your boss it's not possible. Offer him a macro behind a toolbar button
which would pop up a pretend status bar with data at that instant rather
than a fully dynamic one. That would be *much* easier and might keep him
happy.
 
B

Brenda

Hi Tony

You said earlier "Alternatively some low level APIs might get you there." I
was wondering if you could explain that a little bit more to me? The
WindowsSelectionChange just doesn't work very well at all. I need something
a little bit better. Thanks for your time!
 
J

Jezebel

APIs are calls to functions within compiled code modules: including, for
your purposes, elements of Windows itself.

Mechanically, it's fairly simple. You declare the API function using
something like --

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal
lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam
As Long, ByVal lParam As Long) As Long

Then call the function as you would any other function in your code

WindowProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam)

In practice, it's hard work: you have to get things exactly right or you can
scramble your system.


Google will find you details of these functions and how to use them.
Specifically, there are API calls that examine, add to, and remove from, the
User Interface message queue, which contains *everything* the user does,
with mouse, keyboard, or whatever else they may be using. You might want to
pursue this out of interest, but this is way more work than you'll want to
get into for the purposes you describe.
 
B

Brenda

Ok, I'm not done asking questions yet. Sorry. Is it possible to use API with
webpages? If so, I might want to look more into it. I really need some kind
of fix so I can see the "status bar" information.

Thanks for your help!
 
T

Tony Jollans

There are restrictions on what is allowed to run inside browsers as it must
not be possible to do anything harmful - otherwise viruses would be
everywhere. Clearly API calls could be used to do harm so some, at least,
must be disallowed. In practice I suspect that none are allowed but I don't
know for sure.
 
B

Brenda

Is there a forum that is more specific to API calls? If that is my only
option, then I need to talk to people more about it. Unless anyone has any
better ideas...
 
T

Tony Jollans

I don't know about a specific API newsgroup - I just had a quick look and
didn't see anything obvious but you could try some of the OS areas. I think
maybe you should also try an IE group and see whether it is going to be
possible at all (and, if so, in what language) before trying to find out
which APIs you need.

I'm sorry but I don't think I can help you any more. Good luck!
 
B

Brenda

Sorry this is becoming so long, but I just had a thought. How do the Smart
Tags work? Wouldn't that have to use some kind of KeyPress event or
something? Or what event do they use?
 
B

BrendaLL

Hi Tony

I was just wondering more about the macros that you were talking about. How
would I add a macro to a single keystroke? Like if I want them to hit the
'w' key, and perform a function behind that?

Or is there an article that talks about that?

Thanks!
 
T

Tony Jollans

Hi Brenda,

I don't know whether *every* possible key combination can be trapped but the
basic code to set the trap is ...

KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyW), _
KeyCategory:=wdKeyCategoryMacro, _
Command:="MyMacroForW"

And then ...

Sub MyMacroForW()

' Do whatever you want here
' Execute whatever the user expects from pressing W
' (Maybe) Do something else here

End Sub

To do this properly you will need to check beforehand what existing key
assignments there are - and (a) make sure they are honoured and (b) reassign
them afterwards.

The mouse is different. To trap mouse actions in the document you can
probably rely on WindowSelectionChange. To trap those in the interface but
outside the document you'll need to intercept every command bar control -
and I don't think you can trap things in the Task Pane but they may not all
matter.

It might all be possible - I really don't know - but it is most definitely a
major undertaking and probably a big performance hit. If I have time I might
look into it one day or --- <jest> if you want to pay me large sums of money
I might do it sooner </jest>
 
B

BrendaLL

Hello! I'm trying to get this to work, because this is the type of thing I
need: http://blogs.msdn.com/pstubbs/archive/2004/12/31/344964.aspx but it is
not working. I put this function in a cell (=GetNumberFromVSTO()) but it
doesn't find that function. Can you try it and see if you can get it to
work? Wait, do you have VSTO? Sorry this post is so long, but I have
learned lots from you guys. Thanks!
 
T

Tony Jollans

Sorry, I do have VSTO but not installed at present.

On the surface I can't see why it wouldn't work - but as this is an Excel
question it would be better asked in an Excel newsgroup.
 

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