Distinguishing between TAB and Return...

I need to be able to tell if a RETURN key or a TAB key is used when a text field in my matrix has been edited. Now that I think about it I need to be able to tell if the user clicks out of the current text field, thus ending the editing of that field.

Currently, I have the text field’s action sent On Enter Only. I want to be able press the ENTER/RETURN key and move to the next text field BELOW the current one and use the TAB key to move ACROSS the matrix. I’d like to be able to update the contents of the matrix regardless of how the editing has been accomplished.

I have read about the textDidEndEditing_ method but I must admit that my eyes start to “glaze over” about half way through it. :lol:

Thanks in advance,

I’m not sure I understand your problem. The text gets updated in the text field cells whenever you finish editing whether by return, tab or clicking out of the cell – the action message doesn’t have to be sent for that to happen. You get the across then down behavior automatically with TAB, and you can put the code necessary to get the down then across behavior in the action method that you get when pressing return (as you posted before in the “A couple matrix questions…” thread). So, what’s the problem? Isn’t this what you want?


Busy weekend–just now getting back to this.

Not all the text fields in the matrix can be edited by the user. When a text field is updated, a calculation routine is called and the matrix is updated. I need to be able to distinguish what caused the editing to finish and respond accordingly.

TAB → calculation routine → let interface select the next appropriate text field (move across then down)
CLICK out of field → calculation routine
ENTER → calculation routine → MY routine to select the next appropriate text field (move down then across)

Hopefully this sheds some light on the situation.

Thanks again,

Then the only new thing you need to do is add:

on control_textShouldEndEditing_(mat, textView)
		log mat's selectedCell()'s stringValue()
		return 1
	end control_textShouldEndEditing_

This method is called however you end your editing, and you can get the text of the selected cell as I’ve shown – you can then add whatever code you need to do your calculations here. This is a delegate method, so your script needs to be the delegate of the matrix, which can be set up in IB.