It is currently Thu Nov 26, 2020 2:48 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [Done] PB5.20 WindowEvent() #PB_Event_Menu and keyboard-lib
PostPosted: Fri Aug 16, 2013 10:22 am 
Offline
User
User

Joined: Mon Apr 23, 2007 9:42 am
Posts: 70
Hi!

If I run this program I'm able to quit the application with cmd+q key combination:

Code:
InitSprite()

OpenWindow(0,0,0,600,800,"test")
OpenWindowedScreen(WindowID(0),0,0,600,800)

Repeat
 
  Repeat
    event = WindowEvent()
    Select event
      Case #PB_Event_CloseWindow
        quit = 1
      Case #PB_Event_Menu
        Select EventMenu()
          Case -1
            quit = 1
        EndSelect
    EndSelect
  Until event = 0

  ClearScreen(RGB(0,255,0))
  FlipBuffers()
 
Until quit


As soon as I try to do something with the keyboard lib, the WindowEvent() #PB_Event_Menu won't be recognised, so I'm not able to terminate the application with cmd+q

Code:
InitKeyboard()
InitSprite()

OpenWindow(0,0,0,600,800,"test")
OpenWindowedScreen(WindowID(0),0,0,600,800)

Repeat
 
  Repeat
    event = WindowEvent()
    Select event
      Case #PB_Event_CloseWindow
        quit = 1
      Case #PB_Event_Menu
        Select EventMenu()
          Case -1
            quit = 1
        EndSelect
    EndSelect
  Until event = 0
 
 
  ExamineKeyboard()
 
  If KeyboardPushed(#PB_Key_Escape)
    quit = 1
  EndIf
 

  ClearScreen(RGB(0,255,0))
  FlipBuffers()
 
Until quit


I'm not able to examine cmd+q with KeyboardPushed() or any other command in the keyboard lib because cmd & co cannot be recognised.
As a workaround Shardik showed me this working code for this problem:

Code:
EnableExplicit

#NSCommandKeyMask = 1 << 20
#NSKeyDown        = 10

Define CurrentEvent.I
Define event.I
Define quit.I
Define SharedApplication.I

SharedApplication = CocoaMessage(0, 0, "NSApplication sharedApplication")

InitKeyboard()
InitSprite()

OpenWindow(0,0,0,600,800,"test")
OpenWindowedScreen(WindowID(0),0,0,600,800)

Repeat
 
  Repeat
    event = WindowEvent()
    Select event
      Case #PB_Event_CloseWindow
        quit = 1
      Case #PB_Event_Menu
        Select EventMenu()
          Case -1
            quit = 1
        EndSelect
    EndSelect
  Until event = 0

  CurrentEvent = CocoaMessage(0, SharedApplication, "currentEvent")

  If CurrentEvent
    If CocoaMessage(0, CurrentEvent, "type") = #NSKeyDown
      If CocoaMessage(0, CurrentEvent, "keyCode") = 12
        If CocoaMessage(0, CurrentEvent, "modifierFlags") & #NSCommandKeyMask
          quit = 1
        EndIf
      EndIf
    EndIf
  EndIf
 
  ExamineKeyboard()

  If KeyboardPushed(#PB_Key_Escape)
    quit = 1
  EndIf
 
  ClearScreen(RGB(0,255,0))
  FlipBuffers()
 
Until quit


Thank you, Gekkonier


Top
 Profile  
Reply with quote  
 Post subject: Re: PB5.20b10 WindowEvent() #PB_Event_Menu and keyboard-lib
PostPosted: Sun Feb 09, 2020 4:00 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14179
Location: France
Fixed.


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 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