On my Mac at least, if it is asleep, pressing a key just wakes it up.
Do you mean pressing a key on a real keyboard or using Keyboard.print() or Keyboard.write() an Arduino emulated keyboard?
Which message do you see in the Utility App "Console" when sleeping/waking up?
The sequence on the Mac should look like this (only some relevant entries):
01.07.13 21:07:28,000 kernel: hibernate_setup(0) took 0 ms
01.07.13 21:07:46,000 kernel: sleep
01.07.13 21:07:46,000 kernel: Wake reason: EHC1
01.07.13 21:08:48,000 kernel: Previous Sleep Cause: 5
01.07.13 21:08:48,000 kernel: The USB device HubDevice (Port 1 of Hub at 0xfd000000) may have caused a wake by issuing a remote wakeup (2)
01.07.13 21:08:48,000 kernel: The USB device Arduino Leonardo (Port 2 of Hub at 0xfd100000) may have caused a wake by issuing a remote wakeup (3)
As you can see in the log it takes up to 18 seconds before the computer really goes to sleep and puts the USB bus in suspend mode. You should wait this time before you wake it up again. Depending on how much RAM you have and the speed of your HDD, it may even take longer.
When a computer is in a Sleep Mode (S3 state)
, the USB bus is suspended and the devices are no longer polled by the host. In this state it is not possible to send any data to the usb host (e.g. keyboard reports) except the remote wakeup.
In the Microsoft article KB841858
I found an answer why different behaviour can be observed on different computers:When a USB device is enabled to wake the computer, the default behavior permits the computer to enter the S1 system power state for standby. Standby is not the S3 system power state. The S1 system power state is a "lighter" system power state than S3. The S1 system power state typically conserves less power than the S3 system power state.
So we are talking about different system standby states and it depends on your operating system, the attached peripherals (on the mainboard and via cable) and some settings which of these states is entered and if the USB bus stays in D0 state or enters D3 state. D0 and D3 can be distinguished by checking UDINT & (1<<SUSPI), but unfortunately SUSPI is cleared in the Arduino USB_GEN ISR.
I can try to handle the Power-State cases differently, but first I have to find a computer which uses S1 state.
Still trying and learning...