Using two boards and one power supply , button trigger question.

I am using two boards , a Mega and a Leonardo for Led switching and Keyboard / Mouse control respectively.
My question is : if I connect my power supply to Vin and Gnd on both boards , do both boards "see" the 5v I apply to the button pins the same? So if I have a button switch on the Mega setting pin 2 HIGH , can I use the same button switch use the same contacts to set pin 3 on the Leonardo HIGH without damaging anything?

if I connect my power supply to Vin and Gnd on both boards , do both boards "see" the 5v I apply to the button pins the same?

Not at all sure what you mean. If you wire both inputs together then yes both boards will see the same logic level.

I am using two boards

Normally a bad idea and classic beginners mistake. There are very few situations where this makes sense.

So if I have a button switch on the Mega setting pin 2 HIGH , can I use the same button switch use the same contacts to set pin 3 on the Leonardo HIGH without damaging anything?

again your words are not very clear, this is electronics you need to be precise. Both boards must have the pins set to be inputs and that will be fine. Anything else might not be.

Note only the grounds need to be connected together not necessarily the 5V.

Normally you should wire switches between the input and ground and enable the internal pull up resistor. Everything else is sub optimal.

So if I have a button switch on the Mega setting pin 2 HIGH, can I use the same button switch use the same contacts to set pin 3 on the Leonardo HIGH without damaging anything?

As mentioned... probably a BAD idea.

Keep in mind that the GPIO PINS are designed to work with logic level signals. Real-world interfacing means you have to make it look like a signal to board. So, Sharing a BUTTON is a great way to create new glitchy problems that you don't need. (What if one board SEES a button press and the other misses it?) Sharing a Logic SIGNAL between boards is, Guess What?.... Perfectly normal.

So, you attach a button to the MEGA, no big deal, you have plenty of pins... and use another MEGA pin to send a "hey, a button got pressed" signal to an available input pin on the LEO.

Always have a common ground.

Thanks for the responses , I did think it was a bad idea but needed to be sure. I am using two boards because I need 13 buttons and 24 leds on the mega and keyboard and mouse controls on the Leonardo. Thanks to pwillard for advising me how to go , I have enough spare pins on the mega for that.

I am using two boards because I need 13 buttons and 24 leds on the mega and keyboard and mouse controls on the Leonardo.

I would go the other way. I would add some port expanders to the Leonardo to give you the I/O you want. I would not use a Mega just because it has more I/O.

Olino:
if I connect my power supply to Vin and Gnd on both boards

Using "Vin" is itself a bad idea!

If you have a Leonardo functioning as a HID, it will presumably be being powered from the USB jack to which it is connected.