Processing key input on a do loop
#3
(04-20-2023, 03:02 PM)mnrvovrfc Wrote: IDK with _KEYDOWN() check also for ASCII codes 48 through 57, and for 46 for decimal point? Will have to test in both loops besides [F12].

Take a look at the table under this entry:

https://qb64phoenix.com/qb64wiki/index.php/KEYDOWN

This program might be confusing but it illustrates what could be done:

Code: (Select All)
dim as integer i, maxi
dim kount as long, breakoff as _byte
dim keystocheck(1 to 20) as long

for i = 1 to 20
    read keystocheck(i)
    if keystocheck(i) = 34304 then maxi = i: exit for
next

print "Press number keys, or period, or F12. Otherwise you can't quit!"
do
    _limit 10
    print kount
    kount = kount + 1
    for i = 1 to maxi
        if _keydown(keystocheck(i)) then breakoff = 1 : exit for
    next
loop until breakoff
print "OUCH!"
end

data 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 34304

WARNING: Don't set the _LIMIT higher than 10 because it might not do any checking of keys! Or that's what it appears. I tested this on EndeavourOS MATE (based on Arch Linux).

Almost forgot to add. If by any chance you want to involve the [SHIFT] key then even more codes will have to be employed such as 34 for dollar sign and 62 for greater-than sign (in an U.S. keyboard). The same with [CTRL], [ALT], the Windows key and any other key that exists that could be used with a different key. Some people might have keyboards which replicates a typewriter in which period always typed period regardless of SHIFT state. That's why I mentioned the > which ASCII code is 62, while that for period/decimal-point is 46.

I had a similar thought, this happens to be the easier part before processing in the outer loop. I will have to get creative converting a number for keydown as input (and using print to actually show the user with the ability to backspace?) I will have to play with it but so far so good!

Thanks for helping  Big Grin
Reply


Messages In This Thread
Processing key input on a do loop - by NasaCow - 04-20-2023, 11:39 AM
RE: Processing key input on a do loop - by NasaCow - 04-21-2023, 12:07 AM



Users browsing this thread: 5 Guest(s)