[Solved] Macro: What key is pressed in key down event

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
mark_orion
Posts: 38
Joined: Thu Oct 02, 2008 11:53 am

[Solved] Macro: What key is pressed in key down event

Post by mark_orion »

I want to write a macro that gets triggered by a "key down" event and reacts depending on what key has been pressed. The "key down" part is easy as the events property of the form control has it, but how do I get the information about WHAT key is down ?
Last edited by mark_orion on Fri Jun 26, 2009 4:36 pm, edited 1 time in total.
OOo 2.4.X on Ubuntu 8.x
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macro needs to know what key is pressed in key down event

Post by FJCC »

I made a text box and set it to trigger a macro on "key down". The macro expected to be passed a parameter oEv. Here is the Macro

Code: Select all

Sub Main(oEv)
xray oEv

End Sub
When I pressed Shift- A I got this from xray

Code: Select all

KeyChar                   char                        "A"   
KeyCode                   integer                     512   
KeyFunc                   integer                       0   
Modifiers                 integer                       1   
Source                    object                            
So oEv.KeyChar is one way to find out what key was pressed.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
mark_orion
Posts: 38
Joined: Thu Oct 02, 2008 11:53 am

Re: Macro needs to know what key is pressed in key down event

Post by mark_orion »

FJCC wrote:I made a text box and set it to trigger a macro on "key down". The macro expected to be passed a parameter oEv. Here is the Macro
So oEv.KeyChar is one way to find out what key was pressed.
Works excellent - thank you!
OOo 2.4.X on Ubuntu 8.x
Post Reply