Subdivide or Vert Connect in one keyboard shortcut

I’m kind of new to Blender Scripting (but not programming in general) and would like some help. I tried to look for a tutorial online but can’t find something this specific yet.

I have set my keyboard shortcut for Subdivide to “C” but notice that “J” in Blender is set to Vert Connect. What I would like to accomplish is combine the two together like this: If two vertices (exactly two and no more) are selected AND both does not share the same Edge, then I would like the Vert Connect operation to take place. Otherwise it will go ahead with the regular “Subdivide.” This save me from having to switch back and forth on the Keyboard. What’s the Blender logic behind this?