(Excuse for my English)
I'm still learning about PureBasic (which I'm liking more and more) and I'm trying to develop small utilities that integrate with the MacOS desktop.
In this code I want to have a chivato that notifies me when 'Caps. Lock' is on. In the original Mac keyboard this is not needed because the keyboard itself includes a led, but there are many external keyboards that do not have this led and sometimes it is cumbersome not knowing when the caps lock is activated and when it is not (for example in a password text-field)
I take this opportunity to ask how can I read the "About" menu of the system bar menu bar? The "About" option is disabled when I run an app built with PureBasic.
Of course, any suggestion will be welcome

Code: Select all
; ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
; Icono_BloqMays
;
; Shows an icon in system menu when 'Caps.Lock' is enabled
;
; Código PureBasic para compilar en MacOS
;
; ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
EnableExplicit
ImportC ""
CGEventSourceKeyState (stateID, key) ; Identificar estado del teclado en MacOS
EndImport
UsePNGImageDecoder()
Global.i icono = CatchImage(#PB_Any, ?icono_capslock )
Procedure Icon_CapsLock(mostrar)
Static statusBar.i,statusItem.i
; Shared app.i
Protected itemLength.CGFloat = 24
If mostrar
If Not statusBar
statusBar = CocoaMessage(0,0,"NSStatusBar systemStatusBar")
EndIf
If Not statusItem
statusItem = CocoaMessage(0,CocoaMessage(0,statusBar,"statusItemWithLength:",itemLength),"retain")
EndIf
CocoaMessage(0,statusItem,"setHighlightMode:",#YES)
CocoaMessage(0,statusItem,"setLength:@",@itemLength)
CocoaMessage(0,statusItem,"setImage:",ImageID(icono))
;; Elmentos opcionales para este icono
;CreatePopupMenu(0)
;MenuItem(0,"Acerca de CapsLock")
;MenuBar()
;MenuItem(1,"Salir de CapsLock")
;CocoaMessage(0,statusItem,"setMenu:",CocoaMessage(0,MenuID(0),"firstObject"))
Else
If statusBar And statusItem
CocoaMessage(0,statusBar,"removeStatusItem:",statusItem)
EndIf
statusItem = 0
If IsMenu(0) : FreeMenu(0) : EndIf
EndIf
EndProcedure
Procedure.q getCapsLock()
#Key_BloqMays = 57
Define.i retorno = Bool ( CGEventSourceKeyState(1, #Key_BloqMays) & 1 )
ProcedureReturn retorno
EndProcedure
Procedure Monitorizar_CapsLock()
Define lapso = 25 ; 25 milisegundos
Define idTimer = 1
Define event
Define salir = #False
Define.s informacion$
informacion$ = ~"Chivato para \"Caps Lock\" versión 0.0.0. :-) \n\n"
informacion$ + ~"Monitoriza el estado de la tecla 'Bloqueo de Mayúsculas'.\n"
informacion$ + ~"Cuando está activa, se muestra un icono en la barra de estado."
If OpenWindow(0, 0, 0, 400, 160, "Monitor para CapsLock",
#PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_Minimize)
Define informacion = TextGadget(#PB_Any, 20, 20, 380, 120, informacion$)
Define btnFinalizar = ButtonGadget(#PB_Any, 140, 120, 120, 30, "Finalizar")
AddWindowTimer(0, idTimer, lapso)
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Timer And EventTimer() = idTimer
Icon_CapsLock(getCapsLock())
EndIf
If event = #PB_Event_Gadget
If EventGadget() = btnFinalizar
salir = #True
EndIf
EndIf
If event = #PB_Event_Menu
Select EventMenu()
Case #PB_Menu_Quit
salir = #True
Case #PB_Menu_About ; <---- Disabled in System Menu ??
Debug "Acerca de"
EndSelect
EndIf
If event = #PB_Event_CloseWindow
salir = #True
EndIf
Until salir
EndIf
EndProcedure
Monitorizar_CapsLock()
DataSection
icono_capslock:
IncludeBinary "iconos/caps_lock.png"
fin_data:
EndDataSection