Page 1 of 1

How to check what combination of keys was pressed?

Posted: Wed Sep 27, 2017 9:45 pm
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.

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

Posted: Fri Sep 29, 2017 8:40 am
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

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

Posted: Fri Sep 29, 2017 9:08 am
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:

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

Posted: Fri Sep 29, 2017 1:36 pm
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? :)

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

Posted: Fri Sep 29, 2017 1:44 pm
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")

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

Posted: Sat Sep 30, 2017 12:01 am
by airsoftsoftwair
Which platform?

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

Posted: Sat Sep 30, 2017 7:32 am
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

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

Posted: Sat Sep 30, 2017 2:09 pm
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.

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

Posted: Fri Dec 22, 2017 10:23 am
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.. :)

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

Posted: Thu Jan 04, 2018 8:26 pm
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