I have the below python script and I wanted to know how to run some of the code when I press a certain key on the keyboard. I want to know how this can be done with python without Blender Game Engine, where I want the python script to be always waiting for any keyboard input.
import bpy
ob = bpy.data.objects['ARMATURE1']
armature = ob.data
#When press a certain keyboard key let's say H the below code will run
for bone in armature.bones:
print(bone.name)
#or if I pressed J key the below code will run
for bone in armature.bones: print(bone.basename)