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

Creating a macro - Writing a Script - Using the API

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

Postby mark_orion » Thu Jun 25, 2009 10:20 am

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
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

Postby FJCC » Thu Jun 25, 2009 5:40 pm

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   Expand viewCollapse view
Sub Main(oEv)
xray oEv

End Sub


When I pressed Shift- A I got this from xray

Code: Select all   Expand viewCollapse view
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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7200
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

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

Postby mark_orion » Fri Jun 26, 2009 4:35 pm

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
mark_orion
 
Posts: 38
Joined: Thu Oct 02, 2008 11:53 am

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

Postby arfgh » Fri Apr 05, 2019 3:00 pm

so guys.. i have a doubt.. how to detect control key, or alt from the passed event ?
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby UnklDonald418 » Fri Apr 05, 2019 5:25 pm

arfgh
how to detect control key, or alt from the passed event ?

in the example FJCC posted, the XRAY results show
Code: Select all   Expand viewCollapse view
Modifiers                 integer                       1 

Which indicates that in addition the the A key, the Shift Key was also pressed.
https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/KeyModifier.html
Because the Modifiers property is a bit mask, had the results showed
Code: Select all   Expand viewCollapse view
Modifiers                 integer                       3 

then both the Shift and Ctrl keys were pressed (1 + 2)
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby arfgh » Fri Apr 05, 2019 5:32 pm

ok, other doubt... how to detect same from a control that has no input text capabilities from user ? example a label control.
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby UnklDonald418 » Fri Apr 05, 2019 6:16 pm

arfgh
how to detect same from a control that has no input text capabilities from user ? example a label control.

makes no sense. A control that has no user input capabilities will never trigger a Key pressed event.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby arfgh » Fri Apr 05, 2019 6:22 pm

UnklDonald418 wrote:arfgh
how to detect same from a control that has no input text capabilities from user ? example a label control.

makes no sense. A control that has no user input capabilities will never trigger a Key pressed event.


friend, make sense when you want to have an alternate macro programming for a label control acting as ....hyperlink. When click without control button this, when click with control button, that. So should exist a way to do it.....
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby UnklDonald418 » Fri Apr 05, 2019 6:54 pm

A control that has no user input capabilities will never see a Key Pressed event.
A label control will respond to Mouse events. Those events do have the same Modifier properties as Key pressed events.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby arfgh » Fri Apr 05, 2019 7:44 pm

I know, I know UnklDonald418, for that reason is asked... but see what i want to do... what way or what solutions we can take ? The easy way was just what i thought... if control is pressed this, and that if not. But the events are on labels... Surely exist some way to do it, or something that acts near....
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby UnklDonald418 » Fri Apr 05, 2019 11:07 pm

A label control also has When receiving focus and When losing focus events, but it will never respond to those either.
Object oriented programming is based on inheritance and code reuse so perhaps they share some code with the Mouse events.
Maybe Mouse inside uses code from When receiving focus and Mouse outside uses code from When losing focus.
Likewise Mouse button pressed and Mouse button released are similar to Key pressed and Key released events.
Only a developer would know for sure.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby arfgh » Fri Apr 05, 2019 11:13 pm

and is there a way to listen for global* keypress event other than the event is listening ?
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby JeJe » Sat Apr 06, 2019 1:09 am

I presume we're talking about dialogs.

You get label control keypress events the same way: create a macro eg

sub label_keypressed(oevt)
msgbox oevt.keycode 'oevt.keychar 'oevt.modifiers

end sub

And assign the key pressed event to that macro.

If you want the label to receive the keypresses then use

dlg.getcontrol("Label1").setfocus

If you want one sub for all your keypress events then make sure just one control always keeps the focus... set tab index to 0 and tab stop to all the other controls to false... and use setfocus to that control if any of the other controls gain the focus.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 519
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby Villeroy » Sat Apr 06, 2019 1:19 am

Simply assign the event you are interested in to macro My_Macros>MriLib>Module1>MRI
It shows you everything about the event including the source object.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26868
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby UnklDonald418 » Sat Apr 06, 2019 4:57 pm

Or assign a hot-key at Tools>Customize>Keyboard
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby arfgh » Sun Apr 07, 2019 1:01 am

that hot-key is a possible way but... i dont want to split in two subroutines... just only that detects control key pressed or not.. It's more proper, isnt it ?
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby UnklDonald418 » Sun Apr 07, 2019 4:07 am

In Base if the macro is assigned to the hot key Ctrl+F9, only that key combination will trigger the macro.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby JeJe » Sun Apr 07, 2019 8:36 pm

I'm really not following what you want to do, but as you're on windows you can use the windows api to test whether the control key is down. Put this code in a module, run it, and press the control key. It will run forever if you don't press the control key.


Code: Select all   Expand viewCollapse view

   Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer


sub checkforControlkeyDown

   do
      If GetAsyncKeyState( &h11) Then
         msgbox "ctrl pressed"
         exit do
      end if
   loop


End Sub

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 519
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby arfgh » Sun Apr 07, 2019 9:06 pm

that was what i was thinking these days... if we can use win32 api in our macros....
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby arfgh » Tue Apr 09, 2019 4:21 pm

JeJe wrote:I'm really not following what you want to do, but as you're on windows you can use the windows api to test whether the control key is down. Put this code in a module, run it, and press the control key. It will run forever if you don't press the control key.


Code: Select all   Expand viewCollapse view

   Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer


sub checkforControlkeyDown

   do
      If GetAsyncKeyState( &h11) Then
         msgbox "ctrl pressed"
         exit do
      end if
   loop


End Sub




Anyways that tip was amazing and works like a charm. But i cant understand the reason to limit key events depending on the controls. Because for example imagine the follow: we have an image control and we want to maximize it when move the mouse over it, but only when we have control key pressed. That example make sense a lot... but i figure that image control doesnt throw key event like label one....
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby Villeroy » Tue Apr 09, 2019 7:04 pm

Once again: This is NOT a development suite for database solutions. It is an office suite with a download size of less than 200 MB, including all the components and 2 macro languages, help files and a database engine. The form controls were made in the 90ies (StarOffice 5?) and did not change since then.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26868
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby arfgh » Tue Apr 09, 2019 7:39 pm

I dont care Villeroy, At the moment i have seen how it is possible to achieve all kind of solutions, and with each update, AOO works better and better.
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm

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

Postby Villeroy » Tue Apr 09, 2019 8:23 pm

Which updates are you talking about? OpenOffice has not been updated significantly since many years.

P.S: latest Base features added in 2012: https://wiki.openoffice.org/wiki/Base/N ... res_in_3_4
Last edited by Villeroy on Tue Apr 09, 2019 10:22 pm, edited 1 time in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26868
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby UnklDonald418 » Tue Apr 09, 2019 9:45 pm

we have an image control and we want to maximize it when move the mouse over it, but only when we have control key pressed

Add this near the beginning of you image resize macro to check for the Ctrl key
Code: Select all   Expand viewCollapse view
REM use AND to also capture Ctrl key modifier combinations
if  (oEv.Modifiers AND com.sun.star.awt.KeyModifier.MOD1) = 0   then
  exit sub
end if

Link your resize macro to a Mouse moved event on an image control.
Now move the mouse cursor over the image and press the Ctrl key to resize the image.
If you also want to be able to hold down the Ctrl key and then move the mouse cursor over the image control, add a link to the Mouse inside event .
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby Villeroy » Tue Apr 09, 2019 10:23 pm

Since 6 years we write all the macros for this idiot. He does not understand any hints until you explicitly tell him what to do exactly.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26868
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby arfgh » Thu Apr 11, 2019 12:43 pm

Villeroy wrote:Since 6 years we write all the macros for this idiot. He does not understand any hints until you explicitly tell him what to do exactly.


idiot ? the most probable is that i kick ass you totally on other kind of programming languages. The reason that you seem an expert with AOO api dont make you a wise man... in fact who is the idiot ? the idiot or the idiot that call others idiot ?
have a nice day Mr. wiseman.
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 443
Joined: Tue Mar 05, 2013 6:44 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests