Author |
Message |
SNIPERDUDE
|
Posted: Mon Jun 02, 2008 11:15 am Post subject: 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...
code: |
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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
apomb
|
Posted: Mon Jun 02, 2008 12:31 pm Post subject: 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
|
Posted: Mon Jun 02, 2008 2:47 pm Post subject: 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
|
Posted: Mon Jun 02, 2008 2:56 pm Post subject: 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?
Turing: | 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
|
Posted: Mon Jun 02, 2008 2:59 pm Post subject: RE:Help with typing problem |
|
|
what are you running?
Getche?
...checking |
|
|
|
|
|
apomb
|
Posted: Mon Jun 02, 2008 3:01 pm Post subject: 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
|
Posted: Mon Jun 02, 2008 3:23 pm Post subject: 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 :
code: | loop
if hasch then
put getchar ..
end if
end loop |
|
|
|
|
|
|
apomb
|
Posted: Mon Jun 02, 2008 3:25 pm Post subject: Re: Help with typing problem |
|
|
richcash @ Mon Jun 02, 2008 3:23 pm wrote: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Mon Jun 02, 2008 4:38 pm Post subject: 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
|
Posted: Mon Jun 02, 2008 4:46 pm Post subject: 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.
code: | var chars : array char of boolean
loop
Input.KeyDown (chars)
if hasch then
put "yes"
end if
end loop |
insectoid wrote:
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.
apomb wrote:
who is this Compwiz you're talking about?
Oops! |
|
|
|
|
|
SNIPERDUDE
|
Posted: Tue Jun 03, 2008 6:38 am Post subject: 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
|
Posted: Tue Jun 03, 2008 8:04 am Post subject: 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
|
Posted: Tue Jun 03, 2008 8:21 am Post subject: RE:Help with typing problem |
|
|
'hasch' = has charector
aka does the user push any key, it checks if a key has been pushed |
|
|
|
|
|
apomb
|
Posted: Tue Jun 03, 2008 8:22 am Post subject: RE:Help with typing problem |
|
|
i believe it detects whether any key is pressed. |
|
|
|
|
|
Tallguy
|
Posted: Tue Jun 03, 2008 8:23 am Post subject: RE:Help with typing problem |
|
|
basically yes |
|
|
|
|
|
|