#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    1
    Rep Power
    0

    Using many keys at the same time


    I would like to use many keys in the keyboard at the same time.

    For example:

    If I press the "a" key something happens. And if I also press in the "s" key something else will happen and så on. What I mean is that I would like to be able to press many keys at the same time and every keypress will result to an action independently from each other.

    How to do that in Delphi?

    I am using Delphi 5
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Trap the OnKeyPress event for the form, check what key has been pressed and act accordingly. The OnKeyPress event occurs once for each keystroke.
    Code:
    procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    var
    	ch : char;
    begin
    	ch := Upcase(Key);
    	case ch of
    		'A':
    			DoSomething;
    		'S':
    			DoSomethingElse;
    		'D':
    			DoSomethingStrange;
    		else
    			DoDefaultAction;
    	end;
    end;
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo