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 8:39 am
Location: Poland

How to check what combination of keys was pressed?

Post by peceha »

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: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

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

Post by Allanon »

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

Code: Select all

If msg.key = "r" And IsKeyDown("RCONTROL")
   ...your code here
EndIf
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

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

Post by peceha »

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: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

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

Post by Allanon »

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? :)
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

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

Post by peceha »

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: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

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

Post by airsoftsoftwair »

Which platform?
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

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

Post by peceha »

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: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

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

Post by airsoftsoftwair »

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: 32
Joined: Wed Oct 11, 2017 9:13 am

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

Post by Figgy78 »

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: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

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

Post by airsoftsoftwair »

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