Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Backspace Key
#1
Hi
I am working with some keydown event codes, but I can't seem to find the key code for the backspace key. 
Could you kindly advise me? Thank you!

Code:
#win32
set window "KEYDOWN",200,100,false,4
set redraw off

while not keydown(KEY_ESCAPE)
    set color 0,0,0
    cls
   
    set color 255,255,255
    set caret 10,10
    if keydown(KEY_INSERT) wln "Insert"
    if keydown(KEY_DELETE) wln "Delete"
    if keydown(KEY_HOME) wln "Home"
    if keydown(KEY_END, true) wln "End"
    if keydown(KEY_PAGE_UP) wln "Page Up"
    if keydown(KEY_PAGE_DOWN) wln "Page Down"
    'if keydown(KEY_BACKSPACE) wln "Backspace"
   
    redraw
    fwait 10
wend
Reply
#2
To tell you the truth, I have never needed to code a program that required backspace...

As a work-a-round... The ASCII value for backspace is 8. I suppose you could probably use:
if inkey() = 8 then wln "Backspace"
The "timing" of the key press and or release may not be the same as keydown but it should work... kind of...
Logic is the beginning of wisdom.
Reply
#3
I've just not defined a named constant for it. You can use 8, as johnno suggested, with the regular keydown function:

Code:
if keydown(8)
  ...
endif
Reply
#4
... But if you're planning on doing text input, the inkey function is the way to go - that's what ned/ngui uses.
Reply
#5
Thanks, Johnno and Marcus, for the tips on handling the backspace key in Naalaa—whether it’s using `keydown(8)` or checking if `inkey() = 8`. I’m working on a text-based game, kind of like a fantasy computer or a typing tutor, where I need to catch the backspace key. The game’s not done yet, but I’m hoping to drop an alpha version in the next couple of weeks.

Big Grin
Reply
#6
Well... there two things that you can do that are far better than I can do... 1. Imagine; plan and create a game... and 2. Set yourself a deadline and stick to it... Super impressed!! You must tell me your secret... shhhh... I will hardly tell anyone... Moo Ha Ha Ha....
Logic is the beginning of wisdom.
Reply
#7
(9 hours ago)johnno56 Wrote: Well... there two things that you can do that are far better than I can do... 1. Imagine; plan and create a game... and 2. Set yourself a deadline and stick to it... Super impressed!! You must tell me your secret... shhhh... I will hardly tell anyone... Moo Ha Ha Ha....

Honestly, I don’t have any juicy secrets—I just like keeping my brain in good shape. You know that old saying, “an apple a day keeps the doctor away”? Well, here’s my secret twist (oops, guess I *do* have a secret!): “Write a game in a month and keep the brain fog away!”

Big Grin
Reply
#8
Is the inkey example useful? I don't remember Smile  Here's an example that makes sense.

Code:
set window "test", 640, 480
set redraw off

' input text with 'inkey'.

' allowed characters.
charFilter = []
for i = 32 to 126  charFilter[i] = true
inputString = ""
blinkTimer = 0
while not keydown(KEY_RETURN)
    blinkTimer = (blinkTimer + 1)%60
    c = inkey()
    while c
        if key(charFilter, c)  inputString = inputString + chr(c)
        elseif c = 8  inputString = left(inputString, len(inputString) - 1)
        c = inkey()
    wend
    set color 0, 0, 0
    cls
    set color 255, 255, 255
    set caret 0, 0
    write "Enter something: " + inputString
    if blinkTimer%60 < 30  write "_"
    redraw
    fwait 60
wend

' or just use 'rln'
wln
write "Enter something else: "
otherInputString = rln()
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)