Grasshopper Simulating a Keyboard Button Press (VB?)


I’ve been using Grasshopper for a while now, but have absolutely no idea when it comes to using VB scripting. I’m sure it’s possible using something like SendKeys("{DOWN}") but have no idea where or how this goes in the VBscript tool in Grasshopper to simulate pressing the down arrow key (or any other key).

Can someone please help? I’ve tried putting this line into various places in the default VBscript code but get nothing but errors (because I obviously have no idea when it comes to VB!). If you could show me exactly what the VB script should be to simulate pressing a button on the keyboard that would be awesome.

Thanks in advance :smile:

It’s actually not that easy to simulate keyboard events. SendKeys.Send or SenKeys.SendWait seem to indeed be good starting points, but you still need to make sure the key events are consumed by the correct application.

What are you trying to accomlish exactly?

Thanks @DavidRutten, Maybe that’s why everything I try doesn’t work. If I take a step back what I actually want to happen is to wake up my computer from the screensaver (as simple and complex as that!).

I have an interactive project being used in an art gallery, featuring the Firefly plug-in and some Wii controllers. While it’s easy to just turn all screensaver/sleep modes off the computer, I’d rather let a screensaver run while no-one is around, and wake it up simply by pressing a button on the Wii controller. At the moment even though I have actions prescribed to the buttons in Grasshopper, they won’t stop the screensaver from running. I don’t want visitors to touch the computer, so thought simulating a key-press on the keyboard would be a simple trick to wake it up. Any other ideas are more than welcome!!

Someone uploaded a C# class for accessing screensavers, I think you should start there. Basically you can import the appropriate method from a windows api dll and call it directly. Much better than trying to affect the screensaver by mimicking keyboard or mouse events.

In case you never want the screen saver to start, you could use a usb mouse jiggler, see e.g.

There’s a product for every need, isn’t there? :grinning: I’d never heard of such a need or such a device. But then, it’s been quite a while since I’ve used computers owned and administered by someone else.