Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Multiple key use (I need to disable the first key effect)

JuanJuan Posts: 6Member
I'm using Turbo c++ 3.0.

Im making my first game using graphics.h, its about a car in
the street (up view). each move of the screen means that
the program loops, another move and the program loops again.
Each loop have a cleardevice(), to refresh the screen.

The move is done when a key is hold, (loop,loop,loop,...)
The problem:

When I press a key a hold it, the computer gets the first press, and
A SECOND LATER gets all the following presses (I think its done by the interrupt 9); How can I modify this???????
I tried with some ASM programs posted here in Programmersheaven, but the .h files dont compile OK, I think its because of my old compiler (c++ 3.0).

Is any way to do it without ASM?? or something like that??

THANKS A LOT!!!!

Juan (from Argentine)


Comments

  • CSXMCSXM Posts: 11Member
    Why not to use asm?? It's practically the easiest to do it with asm. In c++ ofcoz you use inline-asm. Here are some instructions how to get past this keyb problem:
    Every time a key is pressed or released interrupt 9 is generated.
    When you trace this interrupt read a byte from port 60h
    if bit 7=0 the key was just pressed
    if bit 7=1 the key was just released
    lower 6 bits make the scan code of the key pressed
    notice that the 7th bit stands for value 128
    If you keep holding the key interrupt 9 keeps generating
    If the key is still down while the next interrupt is generated, port 60h gives the scan code of the key pressed
    When the key is released, the final interrup 9 is generated and the port 60h gives you the scan code+128. (the 7th bit which stands for value 128 was set to 1)
    If 'extended' key was pressed, port 60h returs 224 and interrupt is generated and the scan code can be read from the port during that next interrupt.
    There are very nasty keys: PrtScn and Pause/Break

    PrtScn sends 2 extended characters, 42 and 55, so the port will give you 244, 42, 244, 55. Holding the key down port 60h returns only the values 244 (here an interrupt is generated) and 55. On release, port returns all with the 7th bit set, resulting: 244 (i), 170 (i),244 (i), 183. If shift or ctrl is pressed with PrtScn, only the last 2 values are passed on press and release. With alt+PrtScn port 60h gives only scan code 84.

    Pause/Break sends extended 70 when ctrl is pressed, and at all other times sends following: 225, 29, 69, 225, 157, 197. The key doesn't autorepeat. And releasing the key doesn't send anything.
    So that's a living hell.

    So a little hint. If you don't want to use any extended keys do like this:
    If you get 224 from port 60h after int9, compare the next value to 42, 55 and 183. If there's a match, just ignore it, it belongs to PrtScn (first with pressing, second while pressing and holding, and the last with release). If you get 225 from port 60h, throw the next 5 values away since they belong to Pause/Break.
    Or you just could handle these buttons too and go mad. :)
    And I assure you that you have to use inline-asm to do all this right and cool. Happy coding =)
    -Ahti Komu, Finland

    ps. other coders, if you see something wrong with this, make corrections right away

Sign In or Register to comment.