• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sending a Cmd-V keystroke
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending a Cmd-V keystroke


  • Subject: Re: Sending a Cmd-V keystroke
  • From: Jim Correia <email@hidden>
  • Date: Fri, 26 Mar 2010 22:25:20 -0400

On Mar 25, 2010, at 8:23 PM, Jim Graham wrote:

> This is a problem that occurred a few months back in a project. I Never actually used it in the project but it has bugged me ever since. I have simplified the problem into a small example
>
> There is a window with three NSTextFields and a button. The button is connected to the doPaste action and the fields are outlets

Before explaining why your code, as written doesn’t work, and how to fix it, can you give some background as to why you are doing it this way?

Unless you are trying to write a tool similar to Keyboard Maestro, you probably don’t want to be doing it this way.

- In general, you probably want to modify the model objects programmatically, and have the views react and update their display values.

- In the case that you want to update the views directly, you really ought to be reading the value from the pasteboard and setting the view’s display value programatically.

If this really is an academic exercise in pulling puppet strings on the UI, and you have legitimate reasons for doing so, including them in the original question would have avoided the speculation about why you are doing something which seems superficially crazy.

> 	[pb setString:@"Field 1" forType:NSStringPboardType];
> 	[textField1 becomeFirstResponder];

Problem #1:

You change the first responder to sending -makeFirstResponder: to the window. It may fail if editing could not be committed for he current editor.

> -(void)pasteIt

Problem #2a:

This code assumes that your window is the key window and the application is frontmost.

Problem #2b:

You have posted an event, but until AppKit dequeues the event and processes it, the paste doesn’t actually happen. This is why you eventually get 3 pastes in the last edit field.

- Jim_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Sending a Cmd-V keystroke (From: Jim Graham <email@hidden>)

  • Prev by Date: Re: Sending a Cmd-V keystroke
  • Next by Date: Re: Compiler Warning: 'NSDate' may not respond to '+dateWithTimeInterval:sinceDate:'
  • Previous by thread: Re: Sending a Cmd-V keystroke
  • Next by thread: Re: Sending a Cmd-V keystroke
  • Index(es):
    • Date
    • Thread