<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
We're sorry for our lack of precision.<br>In fact, we're using the Racket/gui library and we would like to know how we can test if two keys are pressed at the same time.<br><br>We're testing if the spacebar is pressed for the battleship shots and we're testing the left and right keys for the battleship moving.<br>We want to know how we can test two keys at the same time, because we would like to allow moving and shot at the same time.<br>We're working in a canvas with a modification on the function on-char, using a case on (send event get-key-code).<br><br>This is our definition of the subclass based on canvas%:<br><br>(define my-canvas% <br> (class canvas%<br> (define/override (on-char evt)<br> (case (send evt get-key-code)<br> ((left) (when (and (> (- (send BATTLESHIP get-x) 5) 0) ;;;Moves the battleship on the left<br> (send BATTLESHIP alive?)<br> (not game-over))<br> (send BATTLESHIP move -8)))<br> ((right) (when (and (< (+ (send BATTLESHIP get-x) 35) LARG-JEU) ;;;Moves the battleship on the left<br> (send BATTLESHIP alive?)<br> (not game-over))<br> (send BATTLESHIP move 8)))<br> ((#\space) (when (and (empty? LIST-SHOT) ;;;Battleship shot<br> (send BATTLESHIP alive?)<br> (not game-over))<br> (begin (set! LIST-SHOT (cons (new shot% (x (+ (send BATTLESHIP get-x) 14))<br> (y (- (send BATTLESHIP get-y) 20))<br> (shooter 0))<br> LIST-SHOT)))))<br> ((#\p) (if pause ;;;Pause for the game<br> (begin (send TIMER start DT)<br> (set! pause #f))<br> (begin (send TIMER stop)<br> (set! pause #t))))<br> ((escape) (begin (send TIMER stop) ;;;Quit game<br> (send FRAME-GAME show #f)<br> (send FRAME show #t)))<br> (else (send this on-paint))))<br> (super-new)))<br><br>We would like to test (space and left) and (space and right).<br><br>We hope we gave enough informations.<br><br>Thank all.<br><br>                                            </div></body>
</html>