modifing the android firmware
===

i want to make an application or more like a tweak for android 
i want to write some code that's gonna work on an android device and will do curtain actions based on an input from a Bluetooth device
this application needs to run in the background at all times (as if it was part of the device's operation system) 
and be getting input every second 
i need it to be able to bring up i custom keyboard i am gonna design and to set up a courser just like in a desktop which can be controlled by the application.

i read about something called a ROM and i dont know if thats what i am looking for.

i also know that the android operation system can be modified or replaced with another operation systems like the one called cyanogen .

i am a beginner and i have got some background in java 

i tried creating an android app but i dont know how to make this thing work on the OS 

i need someone to give me a very detailed explanation cause i know nothing about these stuff