Keyboard library (delete topic please)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Keyboard library (delete topic please)

Post 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 :P

Regards,
Ash.
Last edited by LuCiFeR[SD] on Thu Jun 14, 2012 7:17 pm, edited 2 times in total.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Keyboard library

Post 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()
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Keyboard library

Post 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 :P
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Keyboard library

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Keyboard library (delete topic please)

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Keyboard library (delete topic please)

Post 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 :P
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: Keyboard library (delete topic please)

Post 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
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Keyboard library (delete topic please)

Post 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 :P 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 :P

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 :P. select... case in this instance would be 100% useless. And the more I read this thread haha, the more embarrassed I become by it :P Fred, somebody... please save what little dignity I have left hahahaha and just get rid of this thread! :)
Post Reply