Trapping two keys
#8
Just a note about _KeyClear, it won't help with _KeyDown(), it will clear Inkey$ or _KeyHit.

This is interesting:
Code: (Select All)
    If _KeyDown(18432) Then ky = ky + 1
    If _KeyDown(19200) Then ky = ky + 2
    If _KeyDown(19712) Then ky = ky + 4
    If _KeyDown(20480) Then ky = ky + 8
Instead of _KeyClear you could set ky = 0 but it would be more direct to just execute code like if left arrow then x = x-1 if right arrow then x = x+1, if up arrow then y = y - 1, if down arrow then y = y + 1.

You don't need any GetKey sub with _Keydown(), again it tells you immediately when key number is being held down.
Your problem with _keydown is going to be getting user to release key so several calls doing same thing aren't executed but my alternate suggestion is good for moving character around screen.

Quick HeroX, HeroY moving on screen:
Code: (Select All)
Screen _NewImage(800, 600, 32)
_ScreenMove 250, 50
heroX = 400: heroY = 300 ' middle
Do
    Cls
    Circle (heroX, heroY), 10
    If _KeyDown(19200) Then heroX = heroX - 5
    If _KeyDown(19712) Then heroX = heroX + 5
    If _KeyDown(18432) Then heroY = heroY - 5
    If _KeyDown(20480) Then heroY = heroY + 5
    _Limit 10
Loop
b = b + ...
Reply


Messages In This Thread
Trapping two keys - by PhilOfPerth - 10-01-2022, 01:52 AM
RE: Trapping two keys - by bplus - 10-01-2022, 01:59 AM
RE: Trapping two keys - by PhilOfPerth - 10-01-2022, 02:08 AM
RE: Trapping two keys - by bplus - 10-01-2022, 02:26 AM
RE: Trapping two keys - by Pete - 10-01-2022, 02:38 AM
RE: Trapping two keys - by PhilOfPerth - 10-01-2022, 08:05 AM
RE: Trapping two keys - by Pete - 10-01-2022, 01:07 PM
RE: Trapping two keys - by bplus - 10-01-2022, 03:33 PM
RE: Trapping two keys - by Pete - 10-01-2022, 04:19 PM
RE: Trapping two keys - by PhilOfPerth - 10-01-2022, 11:24 PM
RE: Trapping two keys - by PhilOfPerth - 10-02-2022, 12:04 AM
RE: Trapping two keys - by bplus - 10-02-2022, 01:41 AM
RE: Trapping two keys - by Pete - 10-02-2022, 02:00 AM
RE: Trapping two keys - by PhilOfPerth - 10-02-2022, 02:34 AM
RE: Trapping two keys - by bplus - 10-02-2022, 05:20 PM
RE: Trapping two keys - by mnrvovrfc - 10-02-2022, 07:51 PM
RE: Trapping two keys - by Pete - 10-02-2022, 05:51 PM
RE: Trapping two keys - by James D Jarvis - 10-02-2022, 07:56 PM
RE: Trapping two keys - by bplus - 10-02-2022, 07:58 PM



Users browsing this thread: 5 Guest(s)