Detecting whether a car is running
Nearly every car has a 12V accessory supply which is switched with the key. Typically this powers the radio, and maybe other things like indicator lights, power windows, etc. Of course the specifics of which things are on this supply vary from car to car, but every car has something like this. It is used for any accessory which doesn't need to be on when the car is off, and which might otherwise drain the battery between starts.

Once you've found it, then you could power your device directly from it, or indirectly via a 12V relay.