
-----------------------------------
SNIPERDUDE
Mon Jun 02, 2008 11:15 am

Help with typing problem
-----------------------------------
this has been moved from my other thread...

Still trying to figure out the typing problem for textboxes. 
The problem explains itself when you run it... 



type InputBProp : 
    record 
        Text : string 
        Permit : boolean 
        Time, MaxTime, LastChr : int 
    end record 

var InputB : InputBProp 
var ext : boolean := false 
var key :array char of boolean 


InputB.Text := "" 
InputB.Permit := true 
InputB.Time := 0 
InputB.MaxTime := 1 
InputB.LastChr := 0 


setscreen ("nobuttonbar, offscreenonly, graphics:450;450") 

proc getPermit 
    Input.KeyDown (key) 

    if hasch then 
        InputB.Permit := false 
    else 
        InputB.Permit := true 
        InputB.LastChr := 0 
    end if 
        
        
    if key (KEY_ESC) then 
        ext := true 
    end if 
end getPermit 

proc getKeys 
    %getPermit 

    if InputB.Permit then    
        for i : 32 .. 126 
            if key (chr(i)) and i ~= InputB.LastChr then 
                InputB.Text += chr(i) 
                InputB.Time := 0 
                InputB.LastChr := i 
                exit 
            end if 
        end for 
    end if 
    
    getPermit 
end getKeys 

proc keyTimer 
    if InputB.Time < InputB.MaxTime then 
        InputB.Time += 1 
    end if 
end keyTimer 




loop 
    Input.KeyDown (key) 

    getKeys 
    keyTimer 

    cls 
    put InputB.Text 
    View.Update 
    
    exit when ext 
end loop 




any help to get this typing problem smoothed out would be greatly appreciated.

-----------------------------------
apomb
Mon Jun 02, 2008 12:31 pm

RE:Help with typing problem
-----------------------------------
I'm unable to run Turing code on my computer, so in order for myself to see this error, please specify exactly what is happening.

-----------------------------------
SNIPERDUDE
Mon Jun 02, 2008 2:47 pm

RE:Help with typing problem
-----------------------------------
I am trying to create it so I am able to type normally and have the text come up (as if you were typing in a text box).  But the problem is that when I try, it ends up either becoming too sensitive (you tap the key and two or three characters will be added to the string) or lacking in any sensitivity (you would have to press the key two times maybe to get it to add that character).

I want it to be able to be sensitive only to every speed of typing, but I just can't seem to get it.

btw, why can't you run turing on your comp?

-----------------------------------
apomb
Mon Jun 02, 2008 2:56 pm

Re: Help with typing problem
-----------------------------------
maybe im missing something, but wouldnt entering text be as simple as getche(chr)

whats with all this get permit?

proc getPermit
    Input.KeyDown (key)

    if hasch then
        InputB.Permit := false
    else
        InputB.Permit := true
        InputB.LastChr := 0
    end if  
All of these extra qualifications are probably sending too many input.keydown() processes to your program, therefore not accepting the input as valid.

My sugestion is to try using a more direct way of getting characters from the keyboard.

And its because I dont run windows. ;).

-----------------------------------
SNIPERDUDE
Mon Jun 02, 2008 2:59 pm

RE:Help with typing problem
-----------------------------------
what are you running?

Getche?
...checking

-----------------------------------
apomb
Mon Jun 02, 2008 3:01 pm

RE:Help with typing problem
-----------------------------------
Linux on Desktop and MacOSX on laptop, but thats beside the point...

I remember getche() from when i first was introduced to strings in Turing. 

it echos whatever character is in the brackets out to the screen. (or textbox, in your case)

-----------------------------------
richcash
Mon Jun 02, 2008 3:23 pm

Re: Help with typing problem
-----------------------------------
I agree with CompWiz, you should just use getch. Creating your own function with KeyDown will take more effort and A LOT more memory from the computer.

You can also use getchar which is the function version of getch and requires no extra variable.

The general idea :
loop
    if hasch then
        put getchar ..
    end if
end loop

-----------------------------------
apomb
Mon Jun 02, 2008 3:25 pm

Re: Help with typing problem
-----------------------------------
I agree with  CompWiz, you should just use getch. Creating your own function with KeyDown will take more effort and A LOT more memory from the computer.


who is this Compwiz you're talking about? ;)

but yes, that is basically what im saying. and im hoping you're a bit more familiar with Turing than i am.

-----------------------------------
Insectoid
Mon Jun 02, 2008 4:38 pm

RE:Help with typing problem
-----------------------------------
There is also an error with your string catenation becoming too long. I suppose if you cut off the string and start a new one after a space, it would work better. lol, one of my friends is trying to do a typing program with Input.KeyDown. I told him, "Good luck. It won't work."

-----------------------------------
richcash
Mon Jun 02, 2008 4:46 pm

Re: Help with typing problem
-----------------------------------
Also, hasch and Input.KeyDown do not work together unless Input.KeyDown comes after hasch. This does not produce the desired effect.
var chars : array char of boolean
loop
    Input.KeyDown (chars)
    if hasch then
        put "yes"
    end if
end loop


There is also an error with your string catenation becoming too long. I suppose if you cut off the string and start a new one after a space, it would work better. lol, one of my friends is trying to do a typing program with Input.KeyDown. I told him, "Good luck. It won't work."

There's no point to doing it. Instead of using a char variable (1 byte) you use a char (256 elements) array of boolean (and according to a recent compsci tutorial each boolean takes up 1 byte for some reason).

And also you'll probably end up looping through the entire (or part of the) array to check which key was pressed, making it much less efficient.


who is this Compwiz you're talking about? ;)
Oops! :lol:

-----------------------------------
SNIPERDUDE
Tue Jun 03, 2008 6:38 am

RE:Help with typing problem
-----------------------------------
anywho, getch is pretty much what I want.
Is there any way to do this without the pause?

Is there a way of not using a process?

-----------------------------------
Insectoid
Tue Jun 03, 2008 8:04 am

RE:Help with typing problem
-----------------------------------
Never use processes, they are a curse brought on to us by holtsoft. Use procedures, they are a very slightly flawed gift from god.

Oops, you are using  procedures. There is a difference between the two. 

Just out of curiosity, what does 'hasch' do?

-----------------------------------
Tallguy
Tue Jun 03, 2008 8:21 am

RE:Help with typing problem
-----------------------------------
'hasch' = has charector 
aka does the user push any key, it checks if a key has been pushed

-----------------------------------
apomb
Tue Jun 03, 2008 8:22 am

RE:Help with typing problem
-----------------------------------
i believe it detects whether any key is pressed.

-----------------------------------
Tallguy
Tue Jun 03, 2008 8:23 am

RE:Help with typing problem
-----------------------------------
basically yes

-----------------------------------
SNIPERDUDE
Tue Jun 03, 2008 9:59 am

RE:Help with typing problem
-----------------------------------
sooo...

using getch still brings up a small prob.

I don't want for my entire programme to stop to wait for an input.

Any way around this?

-----------------------------------
apomb
Tue Jun 03, 2008 10:00 am

RE:Help with typing problem
-----------------------------------
getche! with an e.

how exactly are you going to input if your program doesnt wait for input?

-----------------------------------
SNIPERDUDE
Tue Jun 03, 2008 1:00 pm

RE:Help with typing problem
-----------------------------------
I'm using an older turing (the new one doesn't complie right), and it says it's getch.  Besides the point.

Anywho I didn't want the pause because I am making more graphic based programme than text.  I want the text thing so I can create my own inputboxes or text fields.

I may have to end up using a process
:(

-----------------------------------
apomb
Tue Jun 03, 2008 1:02 pm

RE:Help with typing problem
-----------------------------------
getch and getche()

are completely different... however, if you dont want your program to halt every time that code runs, make a conditional statement that only runs the input code when you want it to...

-----------------------------------
SNIPERDUDE
Tue Jun 03, 2008 1:22 pm

RE:Help with typing problem
-----------------------------------
hmmm, I did implement that, but it won't be able to run anything in the back at the same time...

So as long as nobody has any background animations it would work fine.

by the way - what is the difference between
ch := getch
and
getche(ch)

(I believe that's how it works...)?

-----------------------------------
apomb
Tue Jun 03, 2008 1:29 pm

RE:Help with typing problem
-----------------------------------
getche always outputs to the screen... though im not 100% sure of the real difference between them, i do rememeber that getche() is a better one to use.

-----------------------------------
SNIPERDUDE
Tue Jun 03, 2008 1:37 pm

RE:Help with typing problem
-----------------------------------
not really sure I even want to output it to the screen.

Anywho, getch outputs it to the screen as well.

I have checked out the help manual (F10) and my guess is they got rid of getche.  The only one I came across was getch.  I looked on 4.1 and 4.0.1...

not sure why though

-----------------------------------
apomb
Tue Jun 03, 2008 1:41 pm

RE:Help with typing problem
-----------------------------------
okay then, what do you need to check for input from the keyboard for then?

-----------------------------------
richcash
Tue Jun 03, 2008 3:44 pm

Re: Help with typing problem
-----------------------------------
What do you mean the whole program pauses?
if hasch then
     getch (ch)
end if
If you put that in your loop the program won't pause. It will check for a key being pressed and if there isn't one it will move on. I see no need for a process and if I remember correctly processes are a bad mix with keyboard input.

And the above does not directly output to the screen, it stores the last character pressed in the ch variable. If you use Font.Draw instead of put you can easily have a background image or manipulate the font or anything else you can imagine for a textbox.

-----------------------------------
apomb
Tue Jun 03, 2008 3:51 pm

Re: Help with typing problem
-----------------------------------
Ah theres the correct use of getch.

thats exactly right. so therefore 

if hasch then
     getche (ch)
end if

would not only store the keystroke in ch, it would output to the screen.

-----------------------------------
SNIPERDUDE
Wed Jun 04, 2008 6:52 am

RE:Help with typing problem
-----------------------------------
Hmmm, I like the hasch check idea...

and apomb, I still can't find getche.
Gonna use getch.

-----------------------------------
apomb
Wed Jun 04, 2008 8:45 am

RE:Help with typing problem
-----------------------------------
it all depends on what you want the input from the keyboard to do really. 

if getch fits your application, perfect.

-----------------------------------
SNIPERDUDE
Wed Jun 04, 2008 9:12 am

RE:Help with typing problem
-----------------------------------
well, it works...
provided I put "nocursor" in the setscreen.

thanks for the help guys.
Now I can finally move forward in my GUI, and finally submit it (this version at least)

-----------------------------------
jeffgreco13
Wed Jun 04, 2008 10:02 am

Re: Help with typing problem
-----------------------------------
make sure you declare your getch variable properly too.

var ch=string(1)

or something along those lines, look into it.

-----------------------------------
SNIPERDUDE
Wed Jun 04, 2008 2:13 pm

RE:Help with typing problem
-----------------------------------
I know, always do (well, not in some of my older programmes).

-----------------------------------
Insectoid
Thu Jun 05, 2008 8:38 pm

RE:Help with typing problem
-----------------------------------
Oh, thank you. So, it's like an Input.Pause that remebers what key you pressed...and doesn't halt the program...

-----------------------------------
SNIPERDUDE
Fri Jun 06, 2008 6:37 am

RE:Help with typing problem
-----------------------------------
yea, pretty cool - wished I thought of that.

I got it woking, and learned something in the process...

DON'T use hasch and Input.KeyDown in the same area - they cancel each other out.

Antwho, just finishing up the code for it, then gonna clean it up a bit and submit.
