How to check what combination of keys was pressed?

Find quick help here to get you started with Hollywood

How to check what combination of keys was pressed?

Postby 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.
peceha
 
Posts: 110
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

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

Postby 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
User avatar
Allanon
 
Posts: 414
Joined: Sun Feb 14, 2010 8:53 pm
Location: Italy

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

Postby 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:
peceha
 
Posts: 110
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

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

Postby 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? :)
User avatar
Allanon
 
Posts: 414
Joined: Sun Feb 14, 2010 8:53 pm
Location: Italy

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

Postby 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")
peceha
 
Posts: 110
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

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

Postby airsoftsoftwair » Sat Sep 30, 2017 12:01 am

Which platform?
User avatar
airsoftsoftwair
 
Posts: 2240
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

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

Postby 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
peceha
 
Posts: 110
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

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

Postby 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.
User avatar
airsoftsoftwair
 
Posts: 2240
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany


Return to Newbie questions

Who is online

Users browsing this forum: No registered users and 2 guests

cron