1 registered members (AndrewAMD),
1,493
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: inchar with more than one character and inchar_active
[Re: jcl]
#385146
10/13/11 14:22
10/13/11 14:22
|
Joined: May 2007
Posts: 2,043 Germany
Lukas
OP
Programmer
|
OP
Programmer
Joined: May 2007
Posts: 2,043
Germany
|
Well, it might help at some point, but it certainly wouldn't suffice to enable me using inkey() for LBGUI keeping all features for the editboxes.
The first problem would be that I'm pretty sure that inkey accepts more than one key per frame, right? So if I'm unlucky, I might just miss a backspace.
Also, it would be no real solution to disable backspaces, because it would still remove the last character of the inkey string, and there would be no way to prevent that, especially not if the last character and the inkey were hit in the same frame.
I think the easiest solution would be a list / an array that keeps the last, let's say 32 inputs of the inkey() function and a variable that keeps track of how many inputs were made. For example, if I'd write "Gamestudio", then delete the "o", then write "^^" I'd get the following list: "G","a","m","e","s,"t",u","d","i","o",backspace,"^^" For the backspace or other keys, you could maybe use special characters or a wrapper struct. That would have the advantage that I wouldn't have to change so much in the code, as I could just use the inputs like the inchar returns. I could make my editbox ignore the backspace. Also, I wouldn't have to care where the inkey cursor is and I don't have to interpret what's in the inkey string, I'd just get the left-arrow/right-arrow events and could handle them like I already do.
This would work even better if there was a way to make the abort keys (like enter, ESC, F1-12) not abort inkey, so I can handle these myself. I'd also like to be able to make inkey not disable any key variables or events.
|
|
|
Re: inchar with more than one character and inchar_active
[Re: Lukas]
#385177
10/14/11 07:30
10/14/11 07:30
|
Joined: Jul 2008
Posts: 894
TechMuc
User
|
User
Joined: Jul 2008
Posts: 894
|
Lukas: if you want a quick solution. I would really suggest you to overload the engine message function (on_message). In the message loop you get ALL windows key messages and save them on your own way. Please check WM_KEYDOWN and the WM_CHAR message. This solution will always be much more flexible than any way gamestudio will offer to you. The only really important thing is to return the orginal message function afterwards (so that the engine is informed about the keystroke). References: WM_KEYDOWN: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646280(v=vs.85).aspx WM_KEYUP: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281(v=VS.85).aspx WM_CHAR http://msdn.microsoft.com/en-us/library/windows/desktop/ms646276(v=VS.85).aspx Article about robus key message handling: http://blog.tavultesoft.com/2008/06/robust-key-mess.htmlExample from the manual with keystrokes:
LRESULT CALLBACK OriginalHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MyMessageHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (WM_CHAR == message)
{
printf("Char keystroke");
}
else if(WM_KEYDOWN == message) { //...
}
//always handle, do not return above
return OriginalHandler(hwnd,message,wParam,lParam);
}
function main()
{
OriginalHandler = on_message; // store the original message loop
on_message = MyMessageHandler; // and replace it by your own
...
}
If you need any help, just contact me.
Last edited by TechMuc; 10/14/11 07:30.
|
|
|
Re: inchar with more than one character and inchar_active
[Re: TechMuc]
#385178
10/14/11 07:34
10/14/11 07:34
|
Joined: Jul 2008
Posts: 894
TechMuc
User
|
User
Joined: Jul 2008
Posts: 894
|
PS: just for yor understanding: When you interfer in the Message Loop, you will not have any problems with multiple keystrokes in one frame anymore, as the MessageHandler will be called IN the engine frame, and allows you to store ANY key stroke, no matter how you like it. Example:
Normal behaviour:
//your code
....
...
START_ENGINE_FRAME() (wait(1);
...
... KEYSTROKE
...
...
END_ENGINE_FRAME();
//your code
//you are informed HERE about the keystroke
overloading message loop:
//your code
...
...
START_ENGINE_FRAME()
...
...KEYSTROKE()
//your code in message loop
...
...KEYSTROKE
//your code in message loop
...
END_ENGINE_FRAME()
//your code
you are already defined about the keystroke when your normal lite-c code is resumed after the wait(1) again :)
|
|
|
|