It is currently Mon Dec 11, 2017 5:10 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 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: 541
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
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 653
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: 541
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
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 653
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  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


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