In cocoa, How to check a textfield is for password

1.2k Views Asked by At

I am developping an input method on Mac OS. Now I have a problem. I need to switch the input mode to english if the current input text field is for password. But I do not know how to do the check. How can I know the current input field is a password field?

3

There are 3 best solutions below

1
squeeks On

NSSecureTextFieldCells handle text input differently than regular text fields, and by default is set only to allow Roman characters. When a user brings this field into focus, IMEs and other formats should be disabled from the keyboard entry selection so this shouldn't be an issue.

0
zonble On

As squeeks mentioned, you need not to do anything because NSSecureTextFieldCells are supposed to allow merely Roman keyboards. However, Mac OS X 10.6 has a bug, If your Input Method's Info.plist file does not contain the TISIntendedLanguage setting, the secure text fields are not able to tell your Input Method is not a Roman input source.

What you need to do is to add the following lines to your Info.plist file. I take Traditional Chinese for example, please change 'zh-Hant' to your language setting.

<key>TISIntendedLanguage</key>
<string>zh-Hant</string>
0
DongYuwei On

Append below content to a Input Method App's Info.plist, then the Input Method can be used in password textfield:

<key>tsInputMethodCharacterRepertoireKey</key>
<array>
  <string>Latn</string>
</array>