Check if spacebar is pressed inside a NSTextView - objective-c

I have a NSTextView where I need to check when a specific button is pressed. Using ModifierKeyFlags I can check if buttons like shift and control is pressed, but I need to check if SPACE is pressed. Therefore, I cannot use the ModifierFlags (cause it can check some buttons, excluding the spacebar)
So I need a check, that notifies me everytime I press the spacebar in the textfield in my application. Any thoughts? I think it needs to be something like this:
if(spacebar is pressed) {
Dlog(#"give me a notification");
}

Use NSText's delegate.
-(void)textDidChange:(NSNotification *)notification
{
//Check if it has added a spacebar
}

Related

UISegmentedControl determine which button is tapped when momentary = YES

I have a UISegmentedControl element where there are two buttons (i.e "Delete all Points" and "Delete Pt #x"). I don't want the buttons to ever remain selected so I have them set as "momentary = YES". I also don't want to handle click events until AFTER the user has released a button. The problem is, I can't figure out which of the two buttons was pressed within the UISegmentedControl view.
What I've tried:
1) I've tried using the "ValueChanged" event. The nice thing here is I can get the selected index for which button was pressed (even when momentary=YES), but the problem is that this event if triggered when the user presses down... which I don't want. I want the event when the user releases their finger, and at that I only want the event when the user releases WITHIN the button view
2) I've tried using the "Touch Up Inside" event. But it doesn't trigger any events when I tap on one of the buttons...
Any help on this would be appreciated. (Programming in Objective-C)
I'm not sure what you mean when you say "I've tried using the "Touch Up Inside" event." Unless you specify precisely what you tried, with code, that is just a meaningless phrase.
Ideally, you'd want create a method something like the following, and set it up as the button's action:
- (IBAction)myButtonTouched:(id)sender forEvent:(UIEvent *)event {
if (event.type == UIControlEventTouchUpInside) {
// do your thing
}
}
Basically you send every user event for that button to the handler and test for the one you want.

Xcode IBAction and Outlets

I am using same action for multiple uibuttons. Is it possible to get which button is the sender?
E.g. Button 1 has been tagged with outlet1 and button2 with outlet2 etc,
When these buttons are pressed, it will call the same action but based on what the sender is, I want to add my logic
//BY DEFAULT THERE IS A TAG OF BUTTON WHICH IS 0
if(yourButton.tag==0){
//do something
yourButton.tag=1;
}else if(yourButton.tag==1){
//do something
yourButton.tag=0;
}
YOU CAN PERFORM DOUBLE ACTION IN SINGLE OUTLET .
THANK YOU

NSEvent clickCount ignore single click method if double click occurs

Is it possible to ignore the first click if a double click is detected?
The following example will still log the one click even before the two clicks. I want to ignore the single click if there is a double click event.
- (void)mouseUp:(NSEvent *)theEvent {
if (theEvent.clickCount > 1) {
NSLog(#"two clicks %ld", theEvent.clickCount);
} else {
NSLog(#"one click %ld", theEvent.clickCount);
}
}
The purpose of doing this, is when the user single clicks in an NSView I want to perform a method that makes another view or window to appear. However, if the user double clicks inside the NSView then I want a different view or window to appear. The following steps outline this work flow:
user single clicks the NSView to make ViewA appear
user double clicks the NSView to make ViewB appear
The problem that I'm having is the single click is always detected therefore ViewA will always appear. But I do not want ViewA to appear if there is a double click, I just want ViewB to appear when there is a double click.
Unless, you can go back in time, you will need to cancel the previous single tap event somehow.
The easiest way: delay the execution on single tap event, and cancel it out if double click is detected.
[self performSelector:#selector(singleTap) withObject:nil afterDelay:[NSEvent doubleClickInterval]];
/// cancel out
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(singleTap) object:nil];
Or, you can execute single tap action immediately, and write a code to cancel it out if double click is detected. This should be very easy too. Because, if it's hard, there might be something wrong with your UX design.

How to differentiate mouse click from key press for NSButton in IBAction

Currently I have an IBAction for a NSButton, and the NSButton also has a key equivalent. I would like to know if there is a way inside my IBAction function "strike"
- (IBAction)strike:(id)sender
that can tell me whether this action is triggered by a mouse click on the button or a press of the key equivalent of the button?
get the current event using -currentEvent and using if loop check for mouse click count
if([theEvent clickCount]>=1)
{
mouse clicked;
}
else
{
button pressed;
}

Change default insertTab: action in NSSearchfield

I have a view with a nssearchfield a nstableview and a nsmatrix with three radiobuttons. Using delegates i change the selected radiobutton when the searchfield is the firstresponder and the user press tab, that works perfectly but what i want is that the searchfield don't loose the firstresponder when the user press tab
You can sub class NSSearchField and add this function
- (BOOL)resignFirstResponder {
return NO;
}
It will refuse to relinquish first responder status.
Another way is catch the windowDidUpdate notification. These are sent whenever anything changes, including change of focus, so you can check for the firstResponder and make it become first responder again.
[searchField becomeFirstResponder];