Prashant
Prashant

Reputation: 2192

Simulate button click for getting special character

In NSTextView, I can get special characters by pressing a certain key combination. Like to get £ - I would press option + 3.

I have an application, which has menu buttons and an editor. The editor is basically a NSTextView with minor modifications. The requirement is to put a button with name £ on it so that if the user clicks it, £ should get displayed in the NSTextView. The user does not want to press option +3. Is there a way I can simulate the option + 3 key press ?. Or is there a better approach ?.

Upvotes: 0

Views: 218

Answers (1)

Yuji
Yuji

Reputation: 34185

Never, ever think of faking the input. Those key combinations depend on the user's language/keyboard choice in System Preferences.

Instead, just write the action method of the button to insert the required string "£". e.g.

   NSString* pound=@"£";
   [textView insertText:pound];

Done!

Upvotes: 1

Related Questions