Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Processing key input on a do loop
#2
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.
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 mnrvovrfc - 04-20-2023, 03:02 PM



Users browsing this thread: 2 Guest(s)