Detect Control or Alt key from the passed event

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Detect Control or Alt key from the passed event

Post by arfgh »

 Edit: Split from [Solved] Macro: What key is pressed in key down event 
so guys.. i have a doubt.. how to detect control key, or alt from the passed event ?
Last edited by MrProgrammer on Sat Jul 04, 2020 8:42 pm, edited 1 time in total.
Reason: New question in solved topic requires new topic
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Post by UnklDonald418 »

arfgh
how to detect control key, or alt from the passed event ?
in the example FJCC posted, the XRAY results show

Code: Select all

Modifiers                 integer                       1  
Which indicates that in addition the the A key, the Shift Key was also pressed.
https://www.openoffice.org/api/docs/com ... ifier.html
Because the Modifiers property is a bit mask, had the results showed

Code: Select all

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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

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 | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Post by UnklDonald418 »

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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

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 | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Post by UnklDonald418 »

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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

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 | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Post by UnklDonald418 »

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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

and is there a way to listen for global* keypress event other than the event is listening ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

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

Post by JeJe »

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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Post by UnklDonald418 »

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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

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 | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Post by UnklDonald418 »

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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

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

Post by JeJe »

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


	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

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

that was what i was thinking these days... if we can use win32 api in our macros....
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

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


	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 | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

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 | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Post by UnklDonald418 »

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

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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

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

Post by arfgh »

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 | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Post Reply