Event - Keyboard

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Event - Keyboard

Post by syntax error »

Looks like PB is lacking in the event-driven keyboard department.

We have

Code: Select all

#PB_Event_Menu
#PB_Event_Gadget 
What about these extras ...

Code: Select all

#PB_Event_Key       ; after WindowEvent() / WaitWindowEvent()
EventKey()          ; last key pressed    #PB_Key_A ...
EventKeyModifier()  ; last key modifier   #PB_Key_LeftAlt ...
That helps to make the event system more straight forward:

Code: Select all

ev=WaitWindowEvent()

Select ev
  ; GADGET
  Case #PB_Event_Gadget
    Select EventGadgetID()
      Case #gadget1
     EndSelect
  ; KEYBOARD
  Case #PB_Event_Key
     If EventKeyModifier()=#PB_Key_RightControl
       If EventKey()=#PB_Key_A
         Debug "YOU PRESSED RightControl+A"
       EndIf   
     EndIf
  Case #PB_EventCloseWindow
    End
EndSelect
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

yeah... can than do away with the eventwparam()...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

That would be nice.
@}--`--,-- A rose by any other name ..
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Post by syntax error »

Except EventwParam() is a depreiciated command and could disappear anytime (according to Kale).
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

it could be nice with those commands, and i also read kale saying that eventwparam() is a depreciated command.
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Uhm that is the same like Addkeyboardshortcut.
bye,
Daniel
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

DarkDragon wrote:Uhm that is the same like Addkeyboardshortcut.
Nope.

With AddKeyboardshortcut you specify a key or key combination
for what you want an event.
With #PB_Event_Key you get every key the user presses... nice
for getting user input. EventKey() should return the ASCII-Char,
so you can catch the info directly and print the chars on an image.
But there must also be a way to catch control keys like CTRL/STRG,
ALT, Cursor Keys etc..

You can start with something like:

Code: Select all

For a = 0 To 1000
  AddKeyboardShortcut(#WIN,a,a)
Next
...but thats not easy to do for all keys.

With #PB_Event_Key you can get CTRL+ALT+F12 if the user
presses it, without knowing this at coding time.
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Post by syntax error »

Yep. I would keep modifiers (Alt/Ctrl) separate.
Two functions should cover the inputs:

After WaitWindowEvent() or WaitEvent()

EventKey()
returns ASCII code of key pressed

EventKeyModifier()
returns modifier such as LeftCtrl , RightAlt , WinKey

This allows you to immediately ignore any simple key presses if NO modifier was used:

Code: Select all

ev=WaitWindowEvent()

Select ev
  Case #PB_Event_Key
    ; lets test for RCtrl+T  / RCtrl+L / RCtrl+A
    If EventKeyModifier()=#PB_Key_RightControl 
       If EventKey()=Asc("T")
         Debug "YOU PRESSED Right-Control+T" 
       EndIf
       If EventKey()=Asc("L")
         Debug "YOU PRESSED Right-Control+L" 
       EndIf
       If EventKey()=Asc("A")
         Debug "YOU PRESSED Right-Control+A" 
       EndIf
     EndIf
EndSelect
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

syntax, yes
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Event - Keyboard

Post by PB »

> What about these extras ...
> #PB_Event_Key

Hehehe, I've wanted this since Apr 11, 2002:

viewtopic.php?t=3719

Anyway, see my tip at the bottom of this post:

viewtopic.php?p=68206

This tip does not use the EventWParam() command, so it's future-proof.
Post Reply