Is there a way to where when my laptop lid is opened, to automatically press a key?

There may be ways to stop your Mac from sleeping when you close the lid, but none of them are recommended, and I'm not even sure the old ways work anymore.

Option 1: sleepwatcher

As far as automating VLC on system wake, that may be possible with sleepwatcher. You ought to able to simulate a press of the spacebar with a bit of AppleScript:

tell application "System Events"
  key code 49 -- space bar
end tell

but you may need to add a slight pause (I'd start with 3 seconds and then adjust down until it failed) so that the system if fully awake before you send it.

That will also fail if VLC is not the front-most app. (Do you have to enter a password when you open the lid? If so, that's another consideration.)


Option 2: Keyboard Maestro

I would be much more likely to use Keyboard Maestro for this. For one thing, it does a lot more than just this one thing, and it can run that AppleScript I mentioned above.

It could also make sure that VLC is the active application and then press the Playback » Play menu item, which is probably more likely to work more reliably than sleepwatcher can.

The only downside is that Keyboard Maestro isn't free, but IMO it's one of the best purchases you can make for your Mac.