• Advertisement

Archived

This topic is now archived and is closed to further replies.

registering mouse clicks via keyboard

This topic is 5102 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Used C code to plot vertices for primitives, ie lines, rectangles. Joined primitives using glBegin(GL_LINES) etc of opengl. Can display primitives in sequence and reverse with mouse clicks but would like to display primitives sequentially and randomly via the keyboard ''s'' and ''r'' keys respectively. Can select s and r keyboard presses in keyboard process function but can''t figure out how to send the mouse clicks via the keys selected. I know that keyboard and mouse process functions both have mouse-x and mouse-y coordinates as arguments but I can''t figure out a solution. Any help appreciated. -Y

Share this post


Link to post
Share on other sites
Advertisement
From the winuser.h file
Read the top lines


/*
* Virtual Keys, Standard Set
*/

#define VK_LBUTTON 0x01
#define VK_RBUTTON 0x02
#define VK_CANCEL 0x03
#define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */

#define VK_BACK 0x08
#define VK_TAB 0x09

#define VK_CLEAR 0x0C
#define VK_RETURN 0x0D

#define VK_SHIFT 0x10
#define VK_CONTROL 0x11
#define VK_MENU 0x12
#define VK_PAUSE 0x13
#define VK_CAPITAL 0x14

#define VK_KANA 0x15
#define VK_HANGEUL 0x15 /* old name - should be here for compatibility */
#define VK_HANGUL 0x15
#define VK_JUNJA 0x17
#define VK_FINAL 0x18
#define VK_HANJA 0x19
#define VK_KANJI 0x19

#define VK_ESCAPE 0x1B

#define VK_CONVERT 0x1C
#define VK_NONCONVERT 0x1D
#define VK_ACCEPT 0x1E
#define VK_MODECHANGE 0x1F

#define VK_SPACE 0x20
#define VK_PRIOR 0x21
#define VK_NEXT 0x22
#define VK_END 0x23
#define VK_HOME 0x24
#define VK_LEFT 0x25
#define VK_UP 0x26
#define VK_RIGHT 0x27
#define VK_DOWN 0x28
#define VK_SELECT 0x29
#define VK_PRINT 0x2A
#define VK_EXECUTE 0x2B
#define VK_SNAPSHOT 0x2C
#define VK_INSERT 0x2D
#define VK_DELETE 0x2E
#define VK_HELP 0x2F

/* VK_0 thru VK_9 are the same as ASCII ''0'' thru ''9'' (0x30 - 0x39) */
/* VK_A thru VK_Z are the same as ASCII ''A'' thru ''Z'' (0x41 - 0x5A) */

#define VK_LWIN 0x5B
#define VK_RWIN 0x5C
#define VK_APPS 0x5D

#define VK_NUMPAD0 0x60
#define VK_NUMPAD1 0x61
#define VK_NUMPAD2 0x62
#define VK_NUMPAD3 0x63
#define VK_NUMPAD4 0x64
#define VK_NUMPAD5 0x65
#define VK_NUMPAD6 0x66
#define VK_NUMPAD7 0x67
#define VK_NUMPAD8 0x68
#define VK_NUMPAD9 0x69
#define VK_MULTIPLY 0x6A
#define VK_ADD 0x6B
#define VK_SEPARATOR 0x6C
#define VK_SUBTRACT 0x6D
#define VK_DECIMAL 0x6E
#define VK_DIVIDE 0x6F
#define VK_F1 0x70
#define VK_F2 0x71
#define VK_F3 0x72
#define VK_F4 0x73
#define VK_F5 0x74
#define VK_F6 0x75
#define VK_F7 0x76
#define VK_F8 0x77
#define VK_F9 0x78
#define VK_F10 0x79
#define VK_F11 0x7A
#define VK_F12 0x7B
#define VK_F13 0x7C
#define VK_F14 0x7D
#define VK_F15 0x7E
#define VK_F16 0x7F
#define VK_F17 0x80
#define VK_F18 0x81
#define VK_F19 0x82
#define VK_F20 0x83
#define VK_F21 0x84
#define VK_F22 0x85
#define VK_F23 0x86
#define VK_F24 0x87

#define VK_NUMLOCK 0x90
#define VK_SCROLL 0x91

/*
* VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
* Used only as parameters to GetAsyncKeyState() and GetKeyState().
* No other API or message will distinguish left and right keys in this way.
*/

#define VK_LSHIFT 0xA0
#define VK_RSHIFT 0xA1
#define VK_LCONTROL 0xA2
#define VK_RCONTROL 0xA3
#define VK_LMENU 0xA4
#define VK_RMENU 0xA5

#if(WINVER >= 0x0400)
#define VK_PROCESSKEY 0xE5
#endif /* WINVER >= 0x0400 */

#define VK_ATTN 0xF6
#define VK_CRSEL 0xF7
#define VK_EXSEL 0xF8
#define VK_EREOF 0xF9
#define VK_PLAY 0xFA
#define VK_ZOOM 0xFB
#define VK_NONAME 0xFC
#define VK_PA1 0xFD
#define VK_OEM_CLEAR 0xFE


---------------------------------
For an overdose of l33tness, flashbang.nu

Share this post


Link to post
Share on other sites
Thanks for your post. Don''t understand your code. Mine was written in C using Visual C++ 6.0. Here is a bit of my code:



void keyBoardProcess(unsigned char key, int mouseX, int mouseY)
{
GLint x = mouseX;

GLint y = 1000 - mouseY;

int counter = 0;

switch(key) {

case ''e'': case ''E'':

exit(-1);

break;

case ''r'':

createGLUTMenus();

break;

case ''s'':


glutMouseFunc(mouseProcess);


counter++;

sequential(counter);

prev_Scene(counter);

counter--;

break;


default:

break;

}
}

Share this post


Link to post
Share on other sites
quote:
Original post by yoho
Thanks for your post. Don't understand your code. Mine was written in C using Visual C++ 6.0. Here is a bit of my code:



void keyBoardProcess(unsigned char key, int mouseX, int mouseY)
{
...
}


It's not his code. Go to C:\Program Files\Microsoft Visual Studio\VC98\Include and open the winuser.h file. Overlord was refering to the VK_LBUTTON, VK_RBUTTON, and VK_MBUTTON definitions.

VK_LBUTTON = Left Mouse Button
VK_RBUTTON = Right Mouse Button
VK_MBUTTON = Middle Mouse Button

-UltimaX-
Ariel Productions

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on March 5, 2004 8:50:02 PM]

Share this post


Link to post
Share on other sites
Thanks for the explanation. How can I apply those button definitions to display my primitives by pressing r or s keys of keyboard then clicking the mouse?

-Y

Share this post


Link to post
Share on other sites
I hope you realize that if you use anything from winuser.h, your program will be Windows-specific (shame on you, lc_overlord, for just assuming Windows).

Share this post


Link to post
Share on other sites
I''m not using Windows code just C with opengl.

-Y

Share this post


Link to post
Share on other sites
quote:
Original post by merlin9x9
I hope you realize that if you use anything from winuser.h, your program will be Windows-specific (shame on you, lc_overlord, for just assuming Windows).


I know, but the for the lack of a better more unified way of doing these thing''s in, i allways assume windows, since most users use it.

Personaly i try to write my code non OS specific, save for the display init code and keyboard/mouse handeling, but those are contained inside one file so it is easy to port.

But if anone(or will i have to) creates a project called OpenSL(open system layer) that contain''s all these things we need, i''ll be the first one to switch to that system(and if you think SDL, then think again).


Yoho:
How do you read your keys?
What os(or API) are you using?


---------------------------------
For an overdose of l33tness, flashbang.nu

Share this post


Link to post
Share on other sites
Using GLUT callback functions. glutKeyboardFunc() for keyboard and glutMouseFunc for mouse.

processKeyboard(unsigned char key, int x, int y)
{
..........

switch(key) {

case 'r': // if press key r

random(r, 0); // random() needs an integer also.

break;

case 's':

sequential(s, 0); // for sequential mode

break;

}

}
// trying to select between random and sequential mode. Key r or key s should be pressed to select random or sequential mode before mouse clicks. let mouse clicks call random func and send 1 for Scene1, 2 for Scene2 etc. mouse will have to send a char also as required by random().


random(char pass, int data)
{
char k = pass;

if(k == r) {

// idea is if got r from keyboard, enter switch. but char from mouse will change pass and k and deny access to switch. if mouse click sends r keyboard can be bypassed.

switch(data) {

case 1:

drawScene(Scene1); // Scene1 global variable


case 2:

drawScene(Scene2);

...........
}

}
}

-Y



[edited by - yoho on March 7, 2004 10:50:43 AM]

[edited by - yoho on March 7, 2004 10:52:47 AM]

[edited by - yoho on March 7, 2004 10:54:58 AM]

Share this post


Link to post
Share on other sites
Found the answer by placing glutMouseFunc() under the keyboard''s ''s'' key for sequential and under the Keyboard''s ''r'' key for random. glutMouseFunc() was therefore removed from function main(). This placed the mouse process function under the control of the keyboard ''s'' and ''r'' keys.

-Y

Share this post


Link to post
Share on other sites

  • Advertisement