Well, if it’s just about right-clicking independently of where the mouse cursor currently is (= anywhere), then this should serve:
[test] Right-Click at Cursor Position.kmmacros (2.4 KB)
But the contextual menu you get naturally depends on the cursor position in the moment you trigger the macro.
If it’s about invoking the contextual menu on a specific element or of a focused element without moving the cursor there, then you have to use UI scripting, as attempted here.
This is the same script that @Hans-Peter_Henkel has posted as screenshot above. It works in many applications, if an element, for example a word in a text field, is focused (selected).
But for UI scripting usually it’s easier and preferable to get a the same menu item from the regular menu bar menu – if it’s there.