press both two arrows keys

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

press both two arrows keys

Post by problème »

Hello,

I would want to know how to do for have as information , if the user press both the arrow key right and the arrow key up .
I would make a call different command if the user press only arrow right.

Code: Select all

on arrow key k
  test k
end arrow key 

command test k
  if k is "right" then
   command1
  else -- if the user press arrow key up + right 
   command2
   end if
end command

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: press both two arrows keys

Post by dunbarx »

Hi.

The arrowKey messages are sent as each is pressed in turn, so you cannot collect them in a serial way. You can always do something like:

Code: Select all

on arrowkey var
   if var = "left" then put "left" after fld 1
   if  var = "down" then put "down" after fld 1
end arrowkey
But this would require a bit more management

Craig
Last edited by dunbarx on Tue Dec 29, 2015 6:19 pm, edited 1 time in total.
problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: press both two arrows keys

Post by problème »

thanks for your help
Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: press both two arrows keys

Post by Newbie4 »

The keysdown does register the arrow keys which have the following number codes:
left = 65361
up = 65362
right = 65363
down = 65364

To see the key codes, copy the following to your card script:

Code: Select all

on updateScreen
   put keysdown( ) into msg
   send updateScreen to me in 20 millisec
end updateScreen
Then add a button:

Code: Select all

on mouseUp
   updateScreen
end mouseUp
It will show you the codes for all the buttons on the keyboard as you press them.

Also, use the "set" command to move your object. It is faster than the "move" command and the 2 keys (up and right - or whatever) will not look disjointed

(You might also get some more answers and ideas here: https://sites.google.com/a/pgcps.org/li ... rogramming

Hope this helps
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10416
Joined: Fri Feb 19, 2010 10:17 am

Re: press both two arrows keys

Post by richmond62 »

I have been playing around with my arrowKeys and have arrived at a VERY SIMPLE way of doing things:
tort.png
code.png
I have attached the stack so you can see how this works.
Attachments
at.zip
Here's th stack.
(12.37 KiB) Downloaded 327 times
problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: press both two arrows keys

Post by problème »

Thank you so much, you have saved me time.
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: press both two arrows keys

Post by MaxV »

Probably this is less pc clocks consuming, because you avoid infinite loops:

########CODE#######
on keydown
put keysdown() into msg
end keydown

on arrowkey
put keysdown() into msg
end arrowkey
#####END OF CODE#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Post Reply