开发者

keyboard interaction with Cocoa?

Hey guys, I am trying do writ开发者_开发知识库e an application(server) which receives the keyboard instructions from the client and execute them on the server end. It's more like those screen recorders which records your keyboard and mouse events and replay them. For example, you pull up a textedit on the server, type whatever you like on the client and you can see those letters on the server.

I have no clues what materials I should look into, any suggestions?


Ok, the way I see it there's a lot of technology involved in this stack.

  • Capturing keystrokes on the client (use IOKit and the HID Utilities Sample Code for this library... or CGEventTap, there's a nice SO question on that technology that may clear up some questions.)
  • Network communications between client and server.
  • Translate events that you receive via the network communication into actual OS level events on the server side. Perhaps CGPostEvent can help you here (there's an SO question that may point you in the right direction with that)

I've done the first (pain in the rear to figure out, but once you have it it's not too bad), and a little work with the third item (although that is some really deep mojo). The second one is actually probably the easiest (solvable perhaps with the MYNetwork framework, or by classes built-into Cocoa.)


You can use CGEventTap to record events at a fairly low level, and to inject events into the event stream. I have used this for recording and playing back a series of events for testing sometimes.

If you are writing the applications in cocoa, you can implement the sendEvent: method of a custom NSApplication to record all events sent to your application. If the server is also cocoa you can use the same sendEvent: method to process some events.

You can also look at CGRemoteOperation for posting events. It was deprecated by CGEventTap but is simpler to use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜