Intercepting many arrow keys (SOLVED)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Intercepting many arrow keys (SOLVED)
Hello,
I was trying to muove a car on the screen, but I can't understand how to intercept 2 pressed arrow keys.
The following code works only with one arrow key at time. If I'm rotating the car, I can't start moving:
##start card code###
on opencard
muovimac
end opencard
on arrowkey puls
switch puls
case "up"
put the velocita of me into v
add 10 to v
set the velocita of me to v
break
case "down"
put the velocita of me into v
add -10 to v
set the velocita of me to v
break
case "left"
put the angle of image "car" into temp
add 5 to temp
set the angle of image "car" to temp
break
case "right"
put the angle of image "car" into temp
add -5 to temp
set the angle of image "car" to temp
break
end switch
end arrowkey
on muovimac
#prendiamo la velocita'
put the velocita of me into v
put the angle of image "car" into temp
#creaimo una strina del tipo x,y
put -v * sin( pi / 180 * temp) into movimento
put "," after movimento
put -v * cos( pi / 180 * temp) after movimento
move image "car" relative movimento
if v > 0 then
add -1 to v
end if
if v < 0 then
add 1 to v
end if
set the velocita of me to v
send muovimac to me in 0.02 sec
end muovimac
###end card code######
I was trying to muove a car on the screen, but I can't understand how to intercept 2 pressed arrow keys.
The following code works only with one arrow key at time. If I'm rotating the car, I can't start moving:
##start card code###
on opencard
muovimac
end opencard
on arrowkey puls
switch puls
case "up"
put the velocita of me into v
add 10 to v
set the velocita of me to v
break
case "down"
put the velocita of me into v
add -10 to v
set the velocita of me to v
break
case "left"
put the angle of image "car" into temp
add 5 to temp
set the angle of image "car" to temp
break
case "right"
put the angle of image "car" into temp
add -5 to temp
set the angle of image "car" to temp
break
end switch
end arrowkey
on muovimac
#prendiamo la velocita'
put the velocita of me into v
put the angle of image "car" into temp
#creaimo una strina del tipo x,y
put -v * sin( pi / 180 * temp) into movimento
put "," after movimento
put -v * cos( pi / 180 * temp) after movimento
move image "car" relative movimento
if v > 0 then
add -1 to v
end if
if v < 0 then
add 1 to v
end if
set the velocita of me to v
send muovimac to me in 0.02 sec
end muovimac
###end card code######
Last edited by MaxV on Wed Jul 23, 2014 10:56 am, edited 1 time in total.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Intercepting many arrow keys
Buonasera Max,
you can only "catch" ONE arrowkey at a time, not two!
Maybe you can use an additional key (r = rotate?) and "catch" "keysdown()"?
Best
Klaus
you can only "catch" ONE arrowkey at a time, not two!
Maybe you can use an additional key (r = rotate?) and "catch" "keysdown()"?
Best
Klaus
Re: Intercepting many arrow keys
Max.
Is your idea to be able to move the car on the diagonal, and that is why you want to be able to press, say, the "up" and "left" at the same time to move to the upperLeft?
If so, I would suggest that you use the mouse pointer inside a small rectangle, where the position of the pointer in that space moves the car. In this way you can completely control both the direction and speed of the car. This would be a very fun task. Do you see what I mean?
Craig Newman
Is your idea to be able to move the car on the diagonal, and that is why you want to be able to press, say, the "up" and "left" at the same time to move to the upperLeft?
If so, I would suggest that you use the mouse pointer inside a small rectangle, where the position of the pointer in that space moves the car. In this way you can completely control both the direction and speed of the car. This would be a very fun task. Do you see what I mean?
Craig Newman
Re: Intercepting many arrow keys
..........
Last edited by [-hh] on Wed Aug 13, 2014 3:41 pm, edited 1 time in total.
shiftLock happens
-
- Livecode Opensource Backer
- Posts: 10102
- Joined: Fri Feb 19, 2010 10:17 am
Re: Intercepting many arrow keys
Here's a thought:
Use keyDown and trap for the 1,2,3,4,6,7,8 and 9 keys on the numeric keyPad.
This may prove problematic and you may have to use rawKeyDown.
Use keyDown and trap for the 1,2,3,4,6,7,8 and 9 keys on the numeric keyPad.
This may prove problematic and you may have to use rawKeyDown.
-
- Livecode Opensource Backer
- Posts: 10102
- Joined: Fri Feb 19, 2010 10:17 am
Re: Intercepting many arrow keys
This should help with rawKey codes:
Re: Intercepting many arrow keys
..........
Last edited by [-hh] on Wed Aug 13, 2014 3:40 pm, edited 1 time in total.
shiftLock happens
Re: Intercepting many arrow keys
All.
I still say a square "field" where the mouse pointer is moved around is the most fun. It also allows speed control, since if you move the pointer, say, at a 30° angle from a center point, you can direct the car in exactly that direction, but also the distance from that center could set the velocity.
Craig
I still say a square "field" where the mouse pointer is moved around is the most fun. It also allows speed control, since if you move the pointer, say, at a 30° angle from a center point, you can direct the car in exactly that direction, but also the distance from that center could set the velocity.
Craig
-
- Livecode Opensource Backer
- Posts: 10102
- Joined: Fri Feb 19, 2010 10:17 am
Re: Intercepting many arrow keys
Here's my take on this:
a stack with 2 methods.
Crack open the card scripts and have fun.
a stack with 2 methods.
Crack open the card scripts and have fun.
- Attachments
-
- multi_keys.livecode.zip
- Here's the stack.
- (21.19 KiB) Downloaded 229 times
Re: Intercepting many arrow keys
The keysdown solution is the best solution, you can move a car (an image) with just this code:
on arrowkey puls
put the keysdown into temp2
repeat for each item tItem in temp2
switch tItem
case "65362"
put the angle of image "car" into temp
#creaimo una strina del tipo x,y
put -5 * sin( pi / 180 * temp) into movimento
put "," after movimento
put -5 * cos( pi / 180 * temp) after movimento
move image "car" relative movimento
break
case "65364"
#dobbiamo muoverla in indietro rispetto al verso del muso
#prendiamo l'angolo della direzione
put the angle of image "car" into temp
#creaimo una strina del tipo x,y
put 5 * sin( pi / 180 * temp) into movimento
put "," after movimento
put 5 * cos( pi / 180 * temp) after movimento
move image "car" relative movimento
break
case "65361"
put the angle of image "car" into temp
add 1 to temp
set the angle of image "car" to temp
break
case "65363"
put the angle of image "car" into temp
add -1 to temp
set the angle of image "car" to temp
break
end switch
end repeat
end arrowkey
on arrowkey puls
put the keysdown into temp2
repeat for each item tItem in temp2
switch tItem
case "65362"
put the angle of image "car" into temp
#creaimo una strina del tipo x,y
put -5 * sin( pi / 180 * temp) into movimento
put "," after movimento
put -5 * cos( pi / 180 * temp) after movimento
move image "car" relative movimento
break
case "65364"
#dobbiamo muoverla in indietro rispetto al verso del muso
#prendiamo l'angolo della direzione
put the angle of image "car" into temp
#creaimo una strina del tipo x,y
put 5 * sin( pi / 180 * temp) into movimento
put "," after movimento
put 5 * cos( pi / 180 * temp) after movimento
move image "car" relative movimento
break
case "65361"
put the angle of image "car" into temp
add 1 to temp
set the angle of image "car" to temp
break
case "65363"
put the angle of image "car" into temp
add -1 to temp
set the angle of image "car" to temp
break
end switch
end repeat
end arrowkey
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Intercepting many arrow keys
..........
Last edited by [-hh] on Wed Aug 13, 2014 3:40 pm, edited 1 time in total.
shiftLock happens
-
- Livecode Opensource Backer
- Posts: 10102
- Joined: Fri Feb 19, 2010 10:17 am
Re: Intercepting many arrow keys
"Richmond, I would like to add a "else pass rawkeydown" to your code. Without this and with a fast repeat rate the spooling of the keyboard buffer is not interruptable."
As I spent no more than 20 minutes knocking that stack together just to illustrate 2 ways of moving an object that is probably the least of
its problems
As I spent no more than 20 minutes knocking that stack together just to illustrate 2 ways of moving an object that is probably the least of
its problems

Re: Intercepting many arrow keys
..........
Last edited by [-hh] on Wed Aug 13, 2014 3:40 pm, edited 1 time in total.
shiftLock happens
Re: Intercepting many arrow keys (SOLVED)
An old trick about speed up animations is the following: cheat the user eyes!
If your machine is slow, increase angle rotation steps and translation steps
For example, rotation code from:
became:
and so on... You can obtain incredible effects deceiving user sensations.
If your machine is slow, increase angle rotation steps and translation steps

For example, rotation code from:
Code: Select all
put the angle of image "car" into temp
add 1 to temp
set the angle of image "car" to temp
Code: Select all
put the angle of image "car" into temp
add 5 to temp
set the angle of image "car" to temp
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w