Page 1 of 1
Keyboard library (delete topic please)
Posted: Thu Jun 14, 2012 5:51 pm
by LuCiFeR[SD]
I would like the keyboard library altered slightly if possible. While it is usable as it is, I think it would make a lot more sense to have the option to use the commands in a case... Select style way.
Example:
Code: Select all
Procedure Check_Keyboard()
ExamineKeyboard()
Select KeyboardPushed()
Case #PB_Key_W
;other code here
Case #PB_Key_A
;other code here
Case #PB_Key_S
;other code here
Case #PB_Key_D
;other code here
Case #PB_Key_Space
;other code here
EndSelect
Select KeyboardReleased()
Case #PB_Key_Escape
;other code here
EndSelect
EndProcedure
I just think it would give us the option to have much cleaner code than is currently possible with the current If... Else... EndIf. Obviously, if this would effect performance to much, then please feel free to ignore my request
Regards,
Ash.
Re: Keyboard library
Posted: Thu Jun 14, 2012 7:01 pm
by STARGÅTE
the problem is, the keyboard lib is for games, and there are even more keys pushed, so you can't select it.
For your example you can use Shortcuts (see Window-Lib) and use Select EventMenu()
Re: Keyboard library
Posted: Thu Jun 14, 2012 7:11 pm
by LuCiFeR[SD]
ahhh good point! I forgot that it handled multiple keypresses... Thanks for reminding me that my brain is turning to Swiss cheese

I guess this request can be deleted due to my own stupidity

Re: Keyboard library
Posted: Thu Jun 14, 2012 10:47 pm
by MachineCode
STARGÅTE wrote:the problem is, the keyboard lib is for games, and there are even more keys pushed, so you can't select it
But what if you don't want or need to check for multiple keypresses? Lucifer's request is still good in those cases.
Re: Keyboard library (delete topic please)
Posted: Thu Jun 14, 2012 11:16 pm
by STARGÅTE
yes, of course, but what key should be returned when the user presses the same time two keys?
KeyboardPushed() is: "key down, or not down" and not a key-"click".
For KeyboardReleased(), it could work.
So a new feature can be:
KeyboardReleased(#PB_Key_All) return 0 if not key is released, or the key-ID from the released key, instead of 1
Re: Keyboard library (delete topic please)
Posted: Thu Jun 14, 2012 11:25 pm
by LuCiFeR[SD]
nah, to be honest... I thought it was a good idea right up until STARGÅTE pointed out my error in judgement... and he is of course absolutely right. Even though I am currently working on something game related which requires multiple keys to be detected, the logic of why the keyboard lib is how it is, was momentarily forgotten in one of those Red mist style rants I have from time to time.
I just didn't think it through properly and logically. So I still think the request is absolutely pointless and needs deleting

Only reason I wanted it changed at all is because I was just getting mighty pissed off at how much typing I was doing just to handle keyboard events really. I kinda oversimplified the thing in my head is all and like an idiot, wrote it in the bloody forum LOL

Re: Keyboard library (delete topic please)
Posted: Fri Jun 15, 2012 2:04 pm
by kenmo
I don't know if it's exactly what you need, but maybe check out this thread about different ways to handle keyboard input:
http://www.purebasic.fr/english/viewtop ... 13&t=49930
Re: Keyboard library (delete topic please)
Posted: Fri Jun 15, 2012 4:24 pm
by LuCiFeR[SD]
kenmo, There was no inherent need for it to be changed really... I was just grumpy after a bit of furious typing lol

I just would have liked for my code to be a lot cleaner (From a readability standpoint). As functional as the library is as it stands, it is just so visually messy IMHO
So I kinda came up with a rushed concept in my head and just completely overlooked that the keyboard lib handles multiple (simultaneous) keypresses. Next time I will certainly spend a little more time examining an idea in a lot more detail before I post it

. select... case in this instance would be 100% useless. And the more I read this thread haha, the more embarrassed I become by it

Fred, somebody... please save what little dignity I have left hahahaha and just get rid of this thread!
