you need a service that is capable of handling transaction over the physical interface i.e. infra red
this is done similarly on bluetooth with obex
so whatever you choose to create HTTP / ftp session, your source phone should start a session and target has to listen for any connection established
then you can start transferring the file
in another word you need to use an application protocol to interface with lower physical interface which in this case is infra red
infra red by itself does not support such transaction
regarding the key press, there should be some easy way in commandlistener to hook for key press
whose phone are you hacking