Hi!
I would like to have North, South, East and West movement defined by a form button and a keyborad arrow key. Is it possible to assign keyboard arrow keys to VBA form buttons?
Hi,
your question has no releation to MicroStation and is about how VBA works (which is Microsoft responsibility), so I recommend to search on Internet and in Microsoft discussion forums at first (did you?).
In my opinion it's cannot be done easily (and may be not at all) and in fact you want to override standard behaviour when arrow keys are used to navigate throug form items.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Well, I didn't search anywhere else besides VBA forums and books.
I'll see what can be done with my little programming skills.
Thank you, Jan
Gabriela
You can capture key events in a UserForm. This KeyEvents VBA project provides an example.
Regards, Jon Summers LA Solutions
What a brilliant solution!
It's exactly what I was looking for.
Thank you again, Jon.
Regards,
an addition to information from Jon: Based on my experience (and it's the reason why I wrote it's not the easy task) the form receives key events only if it doesn't contain any item, that can receive focus (so e.g. label, group box or disabled text box are fine). But if any "input-able" item exists in the form, not key events are sent to the form.
So if your question is about dialog box with no items with input (read-only form), the example from Jon works fine. Otherwise there is no simple solution.
Hi Jan,
I found out why you said it would be hard to do, when I inserted a command button in the Jon's Form (without changing anything else) and it stoped to receive keys events.
In the beginning, I actually wanted to assign keys to buttons (what seems quite impossible to me), but I can manage the situations and use the Jon's code to do what I need.
Thank you for the enlightenment.
Regards, Gabriela
When you press a key on your computer, you generate a Windows message. That message is routed to the currently active application.
The above is out of MicroStation's control. It's out of the control of any normal Windows application. However, the application is responsible for routing the message to the user interface component that it considers to be active. If you were to write code using the Win32 API then you could intercept a message, and use that message to do whatever you want. To extend Jan's comment, you could divert a keypress message from the widget that has focus to some other code. However, that is a complex process.
To understand how complex that process can be, visit a website that deals with Win32 or Microsoft Foundation Class (MFC) programming.
Microsoft designed VBA to be simple to use. They took out lots of the internal stuff, such as Windows messaging, to make it easy to write code in VBA. More accurately, the VBA UserForm so completely wraps Windows messaging as to make it invisible to the programmer. As a result, it's hard to do what you want with a VBA application.