Forum

input keys and strings (write in csqc UI)

Discuss CSQC related programming.

Moderator: InsideQC Admins

input keys and strings (write in csqc UI)

Postby Nahuel » Wed Jun 05, 2019 2:11 am

Basically I need to know which is the most convenient method to write some string in game using the keyboard.
I can use this string as name to change the nameplayer in multiplayer.
I need to know the correct way for characterers (including capital letters) and numbers to be displayed on screen.
any suggestion? thanks in advvance
hi, I am nahuel, I love quake and qc.
User avatar
Nahuel
 
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: input keys and strings (write in csqc UI)

Postby Spike » Wed Jun 05, 2019 12:26 pm

float(float eventtype, float arg1, float arg2, float devid) CSQC_InputEvent =
{
if (eventtype == IE_KEYDOWN)
{
arg1 is the scancode, aka some KEY_FOO value used for binds etc. values will not change based upon shift+etc keys.
arg2 is the character codepoint that was pressed. typically ascii but may also be full unicode. use chr2str if you want the codepoint as a string. values WILL change according to modifiers, and will (hopefully) be different according to the user's active keymap.
it is not guarenteed that both args will be set at the same time (you might see two events for the same key). there is no IME integration, you may see bursts of codepoints in some situations (like combining/accent keys followed by a non-combinable char).
return (TRUE if you handled it, to prevent the engine from handling it instead);
}
if (eventtype == IE_KEYUP)
{
same as above.
autorepeat may mean multiple keydowns with a single keyup.
there's no guarentee about codepoints, don't depend on arg2 being anything but 0, consider them separate for maximum compat.
return FALSE; //you can return true, but that's generally bad form as it could prevent the engine from triggering release binds.
}
return FALSE; //unknown types of events should return false to signify disinterest/failure to handle them.
};

so for text entry, just strcat(theline, chr2str(arg2)) inside the keydown event when arg2 isn't 0. for backspace and delete you'll have to check the scancode instead, as these keys are non-printing. you can then drawstring them in your drawing code.
Example from menusys: https://sourceforge.net/p/fteqw/code/HE ... dittext.qc (scan==arg1, char==arg2, down===eventtype).
I'm sure other people have their own examples...
Spike
 
Posts: 2899
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: input keys and strings (write in csqc UI)

Postby Nahuel » Wed Jun 05, 2019 3:12 pm

thank you! your answer was very useful, after making use of strzone before the strcat , andI managed to write my line in csqc :D
I still have two questions;

I'm currently using a global string for this:

Code: Select all
string theline;

......

float() .... CSQC_InputEvent =
theline = strzone (strcat (theline, chr2str(arg2)));



when should I call strunzone?
It's not clear to me when I should call it


my other question is dumber,I have some keys assigned to commands (e.g. toggleconsole), is there any way that these don't activate when I'm typing?

ty <3
hi, I am nahuel, I love quake and qc.
User avatar
Nahuel
 
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: input keys and strings (write in csqc UI)

Postby Spike » Thu Jun 06, 2019 12:18 am

Code: Select all
string gah = theglobal;
theglobal = strzone(strcat(theglobal,theextratext));
if (gah) strunzone(gah);

you don't need strzone/strunzone in fte, but qss needs them, and dp is annoying in that it doesn't like strunzone(null_string). be careful to not try unzoning a temp or immediate string though.

return true to keydown events while your text widget is focused if you want the engine to not trigger any binds, or probably your entire menu. note that the engine normally allows only f1-f12 keys to trigger binds when the menu is active.
Spike
 
Posts: 2899
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: input keys and strings (write in csqc UI)

Postby toneddu2000 » Mon Jun 10, 2019 7:58 am

I created for craFTEr a little function for that. You can call Input_KeysReleasedMessageMode() in your CSQC_InputEvent(), when uiMessageMode == FALSE. Pressing ENTER key will store data to the uiMessageText variable (probably I'll change it to inputText)

Of course you have to set when uiMessageMode is TRUE and when it's FALSE, depending on your needs.
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
 
Posts: 1363
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy


Return to CSQC Programming

Who is online

Users browsing this forum: No registered users and 1 guest