How to check what combination of keys was pressed?

Find quick help here to get you started with Hollywood
Post Reply
peceha
Posts: 111
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

How to check what combination of keys was pressed?

Post by peceha » Wed Sep 27, 2017 9:45 pm

Hi,
I'd like to know how to check what combination of keys was pressed.
For example: CONTROL R

Code: Select all

Function p_HandlerFunc(msg)
	Switch(msg.action)
	Case "OnKeyDown":
              ?????????? - what should I put in here ????????????		
	EndSwitch
EndFunction

InstallEventHandler({OnKeyDown=p_HandlerFunc})

Repeat
	WaitEvent
Forever
I know how to do this with IsKeyDown() but have no idea how to use MSG.ACTION for that.

User avatar
Allanon
Posts: 436
Joined: Sun Feb 14, 2010 8:53 pm
Location: Italy
Contact:

Re: How to check what combination of keys was pressed?

Post by Allanon » Fri Sep 29, 2017 8:40 am

Hi!
You can use a combination of checks like this :

Code: Select all

If msg.key = "r" And IsKeyDown("RCONTROL")
   ...your code here
EndIf
----------------------------
[Allanon] Fabio Falcucci
AMC - Creative Development // Docs Site // Support Forum
Support me on Patreon for Hollywood libraries!

peceha
Posts: 111
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

Re: How to check what combination of keys was pressed?

Post by peceha » Fri Sep 29, 2017 9:08 am

Thanks!!
I would never think about it myself :)

Unfortunately it works only with character keys and keys called "control" in manual for isKeyDown() .
It doesn't work for "qualifier keys" :cry:

User avatar
Allanon
Posts: 436
Joined: Sun Feb 14, 2010 8:53 pm
Location: Italy
Contact:

Re: How to check what combination of keys was pressed?

Post by Allanon » Fri Sep 29, 2017 1:36 pm

peceha wrote: Unfortunately it works only with character keys and keys called "control" in manual for isKeyDown() .
It doesn't work for "qualifier keys" :cry:
I don't think to have understood... can you explain a bit more? :)
----------------------------
[Allanon] Fabio Falcucci
AMC - Creative Development // Docs Site // Support Forum
Support me on Patreon for Hollywood libraries!

peceha
Posts: 111
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

Re: How to check what combination of keys was pressed?

Post by peceha » Fri Sep 29, 2017 1:44 pm

Sorry :)

When you open Hollywood documentation on IsKeyDown() command, you will see there is something like:
"control keys": ... END, UP, SPACE, INSERT, F1 ...
"charactrer keys" (from the English alphabet): A,B, C...
"qualifier keys": LSHIFT, LCONTROL, LALT...

What I meant was that:

Code: Select all

If msg.key = "r" And IsKeyDown("RCONTROL")
is not working :shock:

it works with "character keys" or "control keys":

Code: Select all

If msg.key = "r" And IsKeyDown("F1")

Code: Select all

If msg.key = "r" And IsKeyDown("u")

User avatar
airsoftsoftwair
Posts: 2477
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: How to check what combination of keys was pressed?

Post by airsoftsoftwair » Sat Sep 30, 2017 12:01 am

Which platform?

peceha
Posts: 111
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

Re: How to check what combination of keys was pressed?

Post by peceha » Sat Sep 30, 2017 7:32 am

Hi,
I'm talking about windows classic amiga (wb3.1)

the first 4 lines are not showing anything

Code: Select all

Function p_HandlerFunc(msg)
	Switch(msg.action)
	Case "OnKeyDown":
		If msg.key="r" And IsKeyDown("RALT") Then NPrint("ralt r") ;not working
		If msg.key="r" And IsKeyDown("LALT") Then NPrint("lalt r") ;not working
		If msg.key="r" And IsKeyDown("LCONTROL") Then NPrint("lctrl r") ;not working
		If msg.key="r" And IsKeyDown("RCONTROL") Then NPrint("rctrl r") ;not working
		If msg.key="r" And IsKeyDown("a" )Then NPrint("a r")
		If msg.key="r" And IsKeyDown("DEL" )Then NPrint("del r")
		If msg.key="" Then NPrint("control r")
	EndSwitch
EndFunction

InstallEventHandler({
	OnKeyDown=p_HandlerFunc
})


Repeat
	WaitEvent
Forever

User avatar
airsoftsoftwair
Posts: 2477
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: How to check what combination of keys was pressed?

Post by airsoftsoftwair » Sat Sep 30, 2017 2:09 pm

Right, this doesn't work. I think something like this is currently incompatible with the way keyboard events work in Hollywood. I'll have to think about a way to make it possible to listen to combination of keys.

Figgy78
Posts: 30
Joined: Wed Oct 11, 2017 9:13 am

Re: How to check what combination of keys was pressed?

Post by Figgy78 » Fri Dec 22, 2017 11:23 am

airsoftsoftwair wrote:Right, this doesn't work. I think something like this is currently incompatible with the way keyboard events work in Hollywood.
I second this request.
Looking forward to a fix.. :)

User avatar
airsoftsoftwair
Posts: 2477
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: How to check what combination of keys was pressed?

Post by airsoftsoftwair » Thu Jan 04, 2018 9:26 pm

Done. That was a pile of work because it is low level stuff so it had to be implemented for Amiga, Windows, Linux, Mac OS (Carbon), Mac OS (Cocoa), Android, and iOS separately. Since Hollywood's original key event handler is incompatible with modifier keys, there are two new event handlers now: OnRawKeyDown and OnRawKeyUp. With these new handlers it's finally possible to listen to combinations of normal and modifier keys now too.

Code: Select all

- New: Introducing raw key support; this finally allows you to listen to combinations of normal
  keys and modifier keys like SHIFT, ALT, CTRL, and CMD; to get notified about raw key events,
  install the new event handlers "OnRawKeyDown" and "OnRawKeyUp"; the "Key" field of the event
  message will contain either a character in the range from A-Z (always upper case), 0-9,
  NP0-NP9, NPDEC, NPADD, NPSUB, NPMUL, NPDIV (NP = numpad), one of the Hollywood key definitions
  like UP, DOWN, RIGHT, etc. or modifier keys like LSHIFT, RSHIFT, LCONTROL, etc.; note that
  in contrast to "OnKeyDown" and "OnKeyUp", "OnRawKeyDown" and "OnRawKeyUp" will also trigger
  when a modifier key is pressed or released on its own; also note that for the space key you
  will get a key named "SPACE" instead of " " and for the return and enter keys the key that
  is generated will be "RETURN" or "ENTER" instead of a linefeed as it is the case with the
  "OnKeyDown" and "OnKeyUp" events; finally, the message that is sent to your event callback
  will also contain a field named "Modifiers" which contains a bitmask of the modifiers which
  were down at the time the key was pressed; this is just for your convenience; of course you
  can also call IsKeyDown() to check which modifiers are down

Post Reply