让我的 NSSecureTextField 触发 NSButton
我有一个 NSSecureTextField。如何才能在按下键盘上的“Enter”按钮时触发“登录”按钮?谢谢!
I have an NSSecureTextField. How can I make it so that when the 'Enter' button is pressed on the keyboard, the 'login' button is triggered? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将登录按钮本身的键盘等效项设置为
\r
(返回)可能是一个更好的主意。为此,请在 Interface Builder 中选择该按钮,打开属性检查器,然后单击Key Equiv.
弹出按钮,然后按return
键,使其看起来像下图:这将为按钮提供蓝色/石墨色,使其成为“默认”按钮。每当按下
return
或enter
键时,都会自动“单击”此按钮。It's probably a better idea to just set the keyboard equivalent of the Login button itself to
\r
(return). To do that, select the button in Interface Builder, open the attributes inspector, and click in theKey Equiv.
popup button, then press thereturn
key so that it looks like the image below:This will give the button the blue/graphite color making it the "default" button. Whenever the
return
orenter
key is pressed, this button will be "clicked" automatically.您也可以尝试一下这个功能。将 NSSecureTextField 的委托设置为此函数。
当您在 NSSecureTextField 中按 Enter 键时,它将执行。
找到示例此处
编辑:
添加了一个deleteBackward案例来处理退格键,因为该函数忽略退格键。
You can also try this function. Set the delegate of the NSSecureTextField to this function.
It will execute when you hit enter in the NSSecureTextField.
Found example here
EDIT:
Added a deleteBackward case to handle backspace since this function ignores backspace.