It is currently Sat Mar 06, 2021 3:10 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: canvas raw keys: bug or feature? [Linux & Windows]
PostPosted: Sun Sep 01, 2013 3:37 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Apr 24, 2012 5:08 pm
Posts: 542
Location: Ontario, Canada
We've written a number of GUI classes that use the Canvas gadget to give us access to additional events and text manipulation facilities for Buttons, String gadgets, etc. We're getting around the following problem by preprocessing the raw key values from PB, and converting them into custom values -- a single unique value for each key on the keyboard.

The documentation states:

Quote:
#PB_Canvas_Key Returns the key that was pressed or released in a #PB_EventType_KeyDown or #PB_EventType_KeyUp event. The returned value is one of the #PB_Shortcut_... values used by the AddKeyboardShortcut() function. This attribute returns raw key presses.


We've found that this is only partly true and is different for Linux and Windows. The following code can be used to show the problems.

Code:
OpenWindow(0,0,0,200,200,"Canvas Gadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(1, 50, 50, 100, 30, #PB_Canvas_Border | #PB_Canvas_Keyboard | #PB_Canvas_DrawFocus)
SetActiveGadget(1)
Repeat
  iWindowEvent  = WaitWindowEvent()
  Select iWindowEvent
    Case #PB_Event_Gadget
      Select EventType()
        Case #PB_EventType_KeyUp
          Debug GetGadgetAttribute(1, #PB_Canvas_Key)
;        Case #PB_EventType_KeyDown
;          Debug GetGadgetAttribute(1, #PB_Canvas_Key)
;        Case #PB_EventType_Input
;          Debug Chr(GetGadgetAttribute(1, #PB_Canvas_Input))
      EndSelect
  EndSelect
Until iWindowEvent = #PB_Event_CloseWindow


The following conditions must be met in order to generate the correct "#PB_Shortcut_...." values for letters and keypad keys:

Linux (KeyUp): Caps lock on (or the Shift key pressed), Num lock must be on
Linux (KeyDown): Num lock must be on

Windows (KeyUp): Num lock must be on
Windows (KeyDown): Num lock must be on

Rather than generating raw key codes, PB is generating case sensitive codes for letters and keypad keys. Also, the keys for special characters such as comma, semicolon, etc, and the keypad Enter, have no defined "#PB_Shortcut_...." values.

I'd like to know if this is a bug or is the intended behaviour.

Every key should have only one possible code, and the code should be defined in the list of "#PB_Shortcut_...." values, or perhaps in its own set of "#PB_Rawkey_...." values to avoid creating problems for the shortcut feature.

Thanks

_________________
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan


Top
 Profile  
Reply with quote  
 Post subject: Re: canvas raw keys: bug or feature? [Linux & Windows]
PostPosted: Wed Dec 06, 2017 1:19 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1307
Location: right here
I have the same problem.
Code:
OpenWindow(0,0,0,200,200,"Canvas Gadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(1, 50, 50, 100, 30, #PB_Canvas_Border | #PB_Canvas_Keyboard | #PB_Canvas_DrawFocus)
SetActiveGadget(1)

Debug "value E: " + #PB_Shortcut_E
Debug "value Left: " + #PB_Shortcut_Left
Debug ""

Repeat
  iWindowEvent  = WaitWindowEvent()
  Select iWindowEvent
    Case #PB_Event_Gadget
      Select EventType()
        Case #PB_EventType_KeyUp
          Debug "up  : " + GetGadgetAttribute(1, #PB_Canvas_Key)
          Select GetGadgetAttribute(1, #PB_Canvas_Key)
            Case #PB_Shortcut_E    : Debug "up  : E"
            Case #PB_Shortcut_Left : Debug "up  : Left"
          EndSelect
       Case #PB_EventType_KeyDown
         Debug "down: " + GetGadgetAttribute(1, #PB_Canvas_Key)
          Select GetGadgetAttribute(1, #PB_Canvas_Key)
            Case #PB_Shortcut_E    : Debug "down: E"
            Case #PB_Shortcut_Left : Debug "down: Left"
          EndSelect
      EndSelect
  EndSelect
Until iWindowEvent = #PB_Event_CloseWindow

'up : Left' is printed but 'up : E' is not, because the value returned by GetGadgetAttribute() is different from #PB_Shortcut_E.
It works in combination with the shift key, and the down event also works ok without shift.
output:
Code:
value E: 69
value Left: 65361

down: 69
down: E
up  : 101
down: 65361
down: Left
up  : 65361
up  : Left


PB 5.61 x64, Ubuntu 16.04


Top
 Profile  
Reply with quote  
 Post subject: Re: canvas raw keys: bug or feature? [Linux & Windows]
PostPosted: Sat Dec 09, 2017 8:49 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Apr 24, 2012 5:08 pm
Posts: 542
Location: Ontario, Canada
@ #NULL

I guess there aren't too many people processing canvas key events - it's been four years since I started this thread. :D

Rod

_________________
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan


Top
 Profile  
Reply with quote  
 Post subject: Re: canvas raw keys: bug or feature? [Linux & Windows]
PostPosted: Sat Dec 09, 2017 7:43 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1307
Location: right here
at least not on linux.
i now use the following:
Code:
              Case #PB_EventType_KeyUp
                tmpKeyUpShortcut = GetGadgetAttribute(canvas, #PB_Canvas_Key)
                If tmpKeyUpShortcut >= 97 And tmpKeyUpShortcut <= 122
                  tmpKeyUpShortcut - 32
                EndIf
                Select tmpKeyUpShortcut
                  Case #PB_Shortcut_A     :   ...
                EndSelect


Top
 Profile  
Reply with quote  
 Post subject: Re: canvas raw keys: bug or feature? [Linux & Windows]
PostPosted: Wed Nov 04, 2020 5:09 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 9:24 am
Posts: 584
Location: Almaty (Kazakhstan)
i try to make some simple game, and a little stuck. how to detect double pressing? left and up arrows for example?

now i get direction from this event selector, but it not detects that "doubled" buttons case
Code:
           Case #MainCanvasWindow
             If EventType() = #PB_EventType_KeyDown
               ButtonCode = GetGadgetAttribute(#MainCanvasWindow, #PB_Canvas_Key)
               Select ButtonCode
                 Case #PB_Shortcut_Left
                   UnitDirection = 1
                   UnitMove = 1

                 Case #PB_Shortcut_Right
                   UnitDirection = 3
                   UnitMove = 1

                 Case #PB_Shortcut_Up
                   UnitDirection = 2
                   UnitMove = 1

                 Case #PB_Shortcut_Down
                   UnitDirection = 4
                   UnitMove = 1
                   
                 Default
                   Debug ButtonCode
                   
               EndSelect
             EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: canvas raw keys: bug or feature? [Linux & Windows]
PostPosted: Wed Nov 04, 2020 5:12 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 9:24 am
Posts: 584
Location: Almaty (Kazakhstan)
wait... i see some small spark in my head :) probably i need trace both case - key press and key relise.



*later

idea was nice, but why windows is loose some keys? i meant for example: i press and hold down, then same pressing - add left. so i hold two buttons, then unhold one of this buttons - and sometimes all is stops. system is didnt see one of holding buttons.

*later
probably is fine :)
Code:
           Case #MainCanvasWindow
             Select EventType()
               Case #PB_EventType_KeyDown
                 ButtonCode = GetGadgetAttribute(#MainCanvasWindow, #PB_Canvas_Key)
                 Select ButtonCode ;{
                   Case #PB_Shortcut_Left
                     UnitDirection = SetBit(UnitDirection, NumToBit(3))
                     UnitOldDirection = 8
                     
                   Case #PB_Shortcut_Up
                     UnitDirection = SetBit(UnitDirection, NumToBit(2))
                     UnitOldDirection = 4
                     
                   Case #PB_Shortcut_Right
                     ;Debug "r"
                     UnitDirection = SetBit(UnitDirection, NumToBit(1))
                     UnitOldDirection = 2

                   Case #PB_Shortcut_Down
                     UnitDirection = SetBit(UnitDirection, NumToBit(0))
                     UnitOldDirection = 1
                   ;}
                 EndSelect
                 
               Case #PB_EventType_KeyUp
                 ButtonCode = GetGadgetAttribute(#MainCanvasWindow, #PB_Canvas_Key)
                 Select ButtonCode ;{
                   Case #PB_Shortcut_Left
                     UnitDirection = ClearBit(UnitDirection, NumToBit(3))
                   Case #PB_Shortcut_Up
                     UnitDirection = ClearBit(UnitDirection, NumToBit(2))
                   Case #PB_Shortcut_Right
                     UnitDirection = ClearBit(UnitDirection, NumToBit(1))                   
                   Case #PB_Shortcut_Down
                     UnitDirection = ClearBit(UnitDirection, NumToBit(0))
                     ;}
                 EndSelect   
             EndSelect


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye