How to stop inchar?

Posted By: hopfel

How to stop inchar? - 10/13/10 21:02

Hey, I'm programming a little textbox using "inchar" (inkey doesn't make sense for that)
But my problem;
I have to stop the input with inchar, "inkey_active = 0;" doesnt work, don't have to explain why. laugh
Is there a possibility for that?

Thank you for help. ^-^
Posted By: EvilSOB

Re: How to stop inchar? - 10/14/10 08:28

Originally Posted By: hopfel
... "inkey_active = 0;" doesnt work, don't have to explain why. laugh ...

Yeah, you DO need to explain why... according to the manual it should work...

?!?
Posted By: hopfel

Re: How to stop inchar? - 10/14/10 20:41

It just works with inkey I guess.
It's just that I tried it out and then the engine crashes.
I looked at the manual too and there it just says,
inkey_active terminates the input with inkey...

Well, and that was just a reading-fail again. -.o'
So it looked clear for me, inkey_active isn't the right solution for that.
Well, but if you say, it should work with inkey_active,
then it's maybe another fault in my code and I'll try it out more exactly.
Thank you. laugh
Posted By: EvilSOB

Re: How to stop inchar? - 10/15/10 08:36

Heres a standalone script showing it in action. (formatting ugly UNTIL pasted into SED)

Run the script and then anything you type gets added to the text object by the "get_inchar()" function.
If you press 'Enter', the function will terminate itself and beep.

BUT, if you press 'F1', the function will terminate (and beep) via "inkey_active" being set to zero in main().

Code:
#include <acknex.h>
#include <default.c>

TEXT* buffer = { string( "Buffer = ");	font="Arial#18b";	flags=SHOW;	}


void get_inchar()
{
	STRING* tmp_str = str_create(" ");		char this_char = 0;
	while((this_char!=1)&&(this_char!=13))	// exit on "1" or "13"
	{													// 13 = pressed enter here
														// 1  = inchar terminated by main
		this_char = inchar(tmp_str);
		if(this_char!=1)   str_cat((buffer.pstring)[0], tmp_str);
		wait(1);   //This wait is !CRITICAL! or it wont react to inkey_active changes
	}
	beep();
}


function main()
{
 	get_inchar();		//start capturing keys into "buffer"

	while(1)
	{
		if(key_f1)		inkey_active = 0;		// terminating capture from
														// "outside" the inchar function
		wait(1);
	}
}


Posted By: hopfel

Re: How to stop inchar? - 10/15/10 11:57

My code looks quiet exactly like your one, there are
just more then one of your function "get_inchar();"
running at the same time, because there are more then
one textbox I can write in. And then, it crashes.
BUT I went out, it works, when I put a wait(1);
BEFORE the inchar. I just don't know why. XD

So, this code crashes:

Click to reveal..
Code:
function inchar_fu()
{
while(1)
{if(inkey_active!=0)
inkey_active=0;

inchar(my_str);
wait(1);}}

function main()
{inchar_fu();
inchar_fu();
inchar_fu();}


And this does not:
Click to reveal..
Code:
function inchar_fu()
{
while(1)
{if(inkey_active!=0)
inkey_active=0;
wait(1);
inchar(my_str);
wait(1);}}

function main()
{inchar_fu();
inchar_fu();
inchar_fu();}


I invented this code, because I haven't my real test-code
on this Netbook, but it should be the same...

Jea, but it works and I'm happy. grin
Thank you EvilSOB for your help. ^-^
Posted By: EvilSOB

Re: How to stop inchar? - 10/16/10 00:42

In my code, if you leave out the wait's then , in essence, only THAT function
is running and able to 'see' what keys are being pressed, and all other
functions are kind-of "on hold" whenever a key is pressed.

The wait in my example allows my get_inchar() to get a character,
and then it waits one frame, to allow other functions to see what key
has been pressed.


With your examples, niether will work 'well' because in both cases the multiple
instances will keep 'fighting' each other for control.
In the first example, the fighting is happening inside a single frame and causes the crash,
where in the second example they just 'take it in turns' to have control, not good methinks.


I need a better understanding your 'overall' project before I cant suggest anything further. PM me with it if you want it kept secret...
Posted By: hopfel

Re: How to stop inchar? - 10/17/10 11:57

Jea, this code above was just an example to show you what I mean, in my code all textboxes have a loop in it like:

while(Wait while I'm not active)wait(1);

There is just a collision with two inputs once, when I
"switch" to another textbox. Was it that, what you meant?

If not, I though my script for the contribution-forum,
so there is no problem with writing my project in here. grin
It's just a very big script, and I don't want to vaste to much of your time...

But if you can have a look on it, it'd be very nice. ^^
Here's the zip with the whole project:
http://ifile.it/95nbu71/Textfeld.zip
(sorry about ifile, I'm not at home and cant upload it on my server...
If I shall upload it on rapidshare or other platforms, just say)

Erm... Jea, the Commands etc. are on german, I couldn't translate it jet.
Hope that's no problem.
It's at least formatted to some degree and quite neat.

Thanks laugh
© 2024 lite-C Forums