Is there any way to capture which keyboard key is pressed or which mouse button is clicked in "On Click" event of a shape?
No, there is no way to do that built-in to AnyLogic: you must left-click all controls and there is no 'press a key' type construct in AnyLogic which would allow you to intercept any key press.
If you want multiple possible user actions, why not just have multiple buttons or, say, a Combo Box and Button?
If you want the button to do different things dependent on the current state of the model you would do that by relevant conditional code (e.g., via Java if
statements) in the Button's action (and you could make the label text of the button dynamic so that the label refers to what the button will do if pressed now, which requires some Java to code the logic for the dynamic value).
What is your actual design requirement?