Archive: Keyboard input


7th September 2004 03:31 UTC

Keyboard input
I've been hunting all day trying to find information one how to get keyboard input working. I can do the mouse input X, Y, and left click (right click can not really be used because it jumps back to windowed avs)

Can any one point me to help file or do they know them selves.


7th September 2004 08:07 UTC

FAQ #16


7th September 2004 09:00 UTC

Took a little bit, but I found the keycodes. They are attached at the bottom. :)

Ok I'll see if I can explain this one:

To get keyboard/mouse input you use the function getkbmouse(value). I will get to the keys in a minute.

Getting the current x and y positions of cursor:
Start a new preset and add a superscope. Delete any code you see. Inside the init box, write n=2. Now make a horizontal line, to do that write this in the per pixel box:


x=(2*i)-1;
y=0;

Now add another superscope and make a vertical line. Delete any code you see and write n=2 in the init box as well. To make a vertical line, just switch the x and y code:

x=0;
y=(2*i)-1;


You don't see any lines, yet because you specified to draw them as dots. To make them lines, select the radio button 'lines' where it says 'Draw as:' at the bottom right.

Now, to get the current x and y positions of the mouse pointer, you use getkbmouse(value). Value will be 1 to get the x position, and 2 to get the y position. The function will return the curosrs' x and y coordinates, respectively.
Add this to the horizontal superscope in the per frame box: mousey=getkbmouse(2);
and change the statement y=0; in the pixel box to y=mousey;
In the vertical superscope add mousex=getkbmouse(1); to the per frame box and change x=0; to x=mousex;

You've got yourself a cross-hair that follows the cursor!

On to the mouse buttons:
To see if the user is pressing the left mouse button you use this: getkbmouse(3)
It's return value will either be 0 (not pressed) or 1 (is pressed). The right mouse button is similar: getkbmouse(4)
It will return either 0 or 1 depending on if the button is pressed down. To use this in code you would have to assign it to a variable like so:

lmouse=getkbmouse(3);


Let's add that to our scopes (both of them) in the frame box.
Now in the pixel box add this:

linesize=if(lmouse,10,1);

All that does is assign linesize the value of 10 if lmouse is 1 (pressed), or the value of 1 if lmouse is 0 (not pressed). If you left-click in the visualization window, the lines "grow".

And finally keyboard input: :D

OK, getting keyboard input is easy, just knowing which number to use isn't. To see if the ALT key is pressed you use getkbmouse(18). We'll add this to our scopes as well. At this point, the frame box for both scopes should look like this:

alt=getkbmouse(18);
mousex=getkbmouse(1);
lmouse=getkbmouse(3);

To put the ALT key to use we'll add this to the pixel box in both scopes:

red=if(alt,1,1);
green=if(alt,0,1);
blue=if(alt,1,1);

If the alt key is 1 (pressed) the colors will be purple, otherwise they will be white.

Here's the zip file with all the key codes on it, ;)

I hope I was helpful.