for a school assignment (kind-of), i am making a pong(tm) - ish game (using pascal for dos w/ graph.tpu), and require the user to be able to move the paddle. what i need to do is find out how to check if certain keys are being pressed... i can give an example in c, using allegro, i go:
if (key[KEY_UP]){move up}
if (key[KEY_ESC]){quit}
_________ Tsutomegi
First of all how well do u know Pascal? A number of years ago I tried to make a network pong game that used the mouse as a control but I lost interest. If your want I find the code and e-mail the code. Other than that it is not a simple as a windows C++ program because u have to access the keyboard interrupts to have any decent control over the keys. I think I got some code for that as well. Any way e-mail me mxk00u@cs.nott.ac.uk
To know if an ascii key is being held down under dos requires interrupts to be replaced and gets quite difficult. For a school assignment, I recommend you do something simpler, like using the shift, alt, ctrl keys. These can be tested through direct memory access. The following program is very crude, but you should be able to read it and take what you need.
This program clears the screen, then keeps writing some things in black text, which is unreadable on a black background. If the appropriate key is being pressed, the text color is changed to grey, making the text visible. You''ll see what I mean.
uses Crt; const Colors: array[boolean] of byte = ($00, $07); begin ClrScr; while not keypressed do begin GotoXY(1, 1); TextAttr := Colors[mem[$40:$17] and 2 = 2]; WriteLn(''Left Shift''); TextAttr := Colors[mem[$40:$17] and 1 = 1]; WriteLn(''Right Shift''); TextAttr := Colors[mem[$40:$18] and 1 = 1]; WriteLn(''Left Ctrl''); TextAttr := Colors[mem[$40:$96] and 4 = 4]; WriteLn(''Right Ctrl''); TextAttr := Colors[mem[$40:$18] and 2 = 2]; WriteLn(''Left Alt''); TextAttr := Colors[mem[$40:$96] and 8 = 8]; WriteLn(''Right Alt'') end end.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform.
You can accept analytics or continue with necessary cookies only.
Learn more