Godot - Check if Controller connected or not - input

I have a small tutorial in my game, which should tell the player how controlls work. There are not many, but it doesn't hurt to show them anyway.
So my game supports controller and keyboard + mouse. If the player has a controller plugged in, I want to show him the controller controls and if not, I want to show him the keyboard + mouse controls.
Now I have something like this already implemented which checks the MOUSE MODE. It works fine, but can only detect the controller if a button or a joystick was moved or pressed.
Is there anyway to check if a controller is connected?
input gdscript controller joystick control

You can use Input.get_connected_joysticks() and then look inside the array if there is a joystick. Also usefull for local multiplayer.
This event joy_connection_changed will also be usefull in some case.

Related

Objective-c: Make a cocoa app to simulate media keys

I'm trying to simulate a press of this media buttons by code in a macbook:
The idea is to pause, rewind... the music with the uibuttons in my app. It's posible to do this? I did't find anything.
Something like this:
- (IBAction)playButtonClick:(id)sender {
//code here to play music, like if we pressed the physical play media key
}
I would draw images for that (probalby in two resolutions, one for retina and one for non-retina, while in most cases a retina version is sufficient) in two variations, one in regular mode and one as if the button is currently pressed.
Then use a simple UIButton object for each of them.
And right, when you create the buttons programmatically, then you can use
- (void)playButtonClick:(id)sender
as target for the play button. However, when you want to create and locate the buttons in Interface Builder or Storyboard Editor respectively, then it should be
- (IBAction)playButtonClick:(id)sender
which enables the IB to allow you to draw the connection to the action within IB accordingly.

In Objective-C/Cocoa, are there global events for when mission control is activated or spaces are changed?

I'm currently working on an OSX menubar app that uses a custom status item view and a NSPopover to display content.
I'm trying to get it to dismiss at times that would make sense like when spaces are changed, since the popover doesn't move spaces like a window does, or when mission controller is activated.
Currently, when in mission control, the NSPopover stays on top as shown in this screenshot.
Currently I'm using NSEvent addGlobalMonitorForEventsMatchingMask: with some mouse event masks and that works alright but doesn't cover all needed events.
So, is there a way to detect when major OS events happen like opening mission control, changing spaces etc?
Any help would be greatly appreciated.
You can get notified of space changes by registering for NSWorkspace's NSWorkspaceActiveSpaceDidChangeNotification. There isn't a notification as such for Mission Control, but you might investigate whether NSWorkspaceDidActivateApplicationNotification or other notifications can be used to determine what you need.
HTH

Controlling NSSegmentedControl with the keyboard

I have a form in my Cocoa app that contains an NSSegmentedControl that I want to be controllable via the keyboard. It seems that NSSegmentedControl is very reluctant to become the first responder, however.
Setting the initial first responder of the window to the segmented control does nothing -- it will not have keyboard focus when the window is first loaded. It does receive focus if I manually set the first responder like this, however:
[segmentedControl.window makeFirstResponder: segmentedControl];
That will work fine if the only part of the form is the segmented control. If I add another field (say, an NSTextField), and I set the nextResponder of the segmented control to that field, the segmented control will never become first responder. Focus will immediately go to the text field, and pressing tab to switch back to the segmented control doesn't work.
I've tried subclassing NSSegmentedControl and overriding acceptsFirstResponder, becomeFirstResponder, etc. to no avail. The only one that makes any difference is resignFirstResponder -- if I return NO from that method then the segmented control will indeed retain focus, but obviously I don't want it to retain focus all the time.
Any ideas on how to get the control to behave like a normal responder?
It's behaving as intended. Not all controls participate in the "key view loop". Full keyboard navigation is turned on through Universal Access in System Preferences for all apps and it's not for individual apps to implement on their own.
It's best not to use a segmented control in a form intended for heavy keyboard entry. NSPopUpButton works more closely to what we all exepect in a web form so it's not as if it's necessarily the wrong choice in your app's UI.
Rather than answer exactly the question you asked (which someone else can do), I humbly suggest you choose on the side of functionality at the cost of a slightly prettier UI element since that prettier UI element wasn't intended to get along with the keyboard.

iPad UIButtons responding to external keyboard input

I'm writing an app based around a calculator-like UI. On an iPad, I'd like the number UIButtons on my calculator UI to respond to the numbers on the external keyboard. I have no text input anywhere in the app, and I'd never want an on-screen keyboard to appear. How do I get my UIButtons to respond to specific key presses as if they'd been touched?
I'd say create a hidden UITextField with the delegate set, make it become the first responder upon viewDidLoad. The keyboard won't appear when a bluetooth keyboard is connected as far as I know, then just check what characters are typed in the shouldChangecharactersInRange and activate the right buttons accordingly.
EDIT: a quick example I just made, https://github.com/benjaminq42/buttonTest , if you wish to have a highlight animation of some sorts you need to create a custom UIButton class. You can use 'setHighlighted' but that 'sticks'.

Mouse events for an NSSegmentedCell subclass?

I'm trying to implement some rudimentary tabs in a Cocoa editor I'm working on. I am using an NSSegmentedControl and adding segments to it as tabs. I'm using a custom NSSegmentedCell subclass for the tabs to draw a little 'x' icon next to the text for closing tabs and so far it's been going pretty smooth.
However, I cannot figure out how to actually process mouse events for the tabs to check if someone moused over (or clicked) the 'x' icon. I tried overriding "mouseMoved" in my NSSegmentedControl subclass, but for some odd reason it stops getting called when I add a new segment to it (I set "setAcceptsMouseMovedEvents" to yes in awakeFromNib, do I have to also set it somewhere else??). NSSegmentedCells, being NSCell subclasses seem to not have any mouse event processing, aside from mouse tracking, which gets triggered only when the control is clicked.
So the question is, how would I properly process mouse events, either in the NSSegmentedControl or in the NSSegmentedCell subclass?
Take a look at NSTrackingArea. You can add a tracking area to your NSSegmentedControl and get mouse-entered events on that to highlight the close button.
As for getting the click events, you're probably best off using a separate NSActionCell subclass for the close button and do some hit testing there.