Page 1 of 1
Event - Keyboard
Posted: Sun Jun 06, 2004 8:30 am
by syntax error
Looks like PB is lacking in the event-driven keyboard department.
We have
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
Posted: Sun Jun 06, 2004 8:38 am
by blueznl
yeah... can than do away with the eventwparam()...
Posted: Sun Jun 06, 2004 9:10 am
by Dare2
That would be nice.
Posted: Sun Jun 06, 2004 9:10 am
by syntax error
Except EventwParam() is a depreiciated command and could disappear anytime (according to Kale).
Posted: Sun Jun 06, 2004 9:29 am
by thefool
it could be nice with those commands, and i also read kale saying that eventwparam() is a depreciated command.
Posted: Sun Jun 06, 2004 9:37 am
by DarkDragon
Uhm that is the same like Addkeyboardshortcut.
Posted: Sun Jun 06, 2004 11:37 am
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.
Posted: Mon Jun 07, 2004 8:31 pm
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
Posted: Mon Jun 07, 2004 8:42 pm
by blueznl
syntax, yes
Re: Event - Keyboard
Posted: Tue Aug 31, 2004 12:30 pm
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.