Using mouse via WinAPI?
-
- Halfling
- Posts: 89
- Joined: Thu Apr 22, 2004 11:22 am
- x 1
Using mouse via WinAPI?
Hello,
Is there some description or sample how to use WinAPI mouse system with Ogre?
Thanks,
Igor
Is there some description or sample how to use WinAPI mouse system with Ogre?
Thanks,
Igor
-
- OGRE Retired Moderator
- Posts: 9481
- Joined: Fri Feb 18, 2005 2:03 am
- Location: Dublin, CA, US
- x 22
Re: Using mouse via WinAPI?
Ogre and input are orthogonal.
Also, what do you mean by "WinAPI mouse system"?
Also, what do you mean by "WinAPI mouse system"?
-
- Halfling
- Posts: 89
- Joined: Thu Apr 22, 2004 11:22 am
- x 1
Re: Using mouse via WinAPI?
Sorry for late reply.xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Classical WM_MOUSE* Windows messages processing.
-
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
Re: Using mouse via WinAPI?
Does this forum look like a Win32 programming forum?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
-
- OGRE Retired Moderator
- Posts: 9481
- Joined: Fri Feb 18, 2005 2:03 am
- Location: Dublin, CA, US
- x 22
Re: Using mouse via WinAPI?
You process them the same as you do for any other Win32 application. The problem you will run into with Ogre, is that the Win32 message dispatching is done in an internal class (WindowEventUtilities) so you'll probably want to make your own Win32 window and embed the Ogre render window in that, so that you have complete control over the message processing. Note, however, what sorts of things the Ogre code does in various scenarios, because you'll need to duplicate it.igorvlassov wrote:Sorry for late reply.xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Classical WM_MOUSE* Windows messages processing.
Of course, you can always subclass the window class and call the Ogre WndProc when yours is done.
-
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 535
Re: Using mouse via WinAPI?
Depending on what you are doing and how adventurous you are, you may want to take a look at WM_INPUT instead of WM_MOUSE.
(I've just spent the last hour or so playing with it).
WM_MOUSE is good for simple cursor stuff, but it can't handle high precision mice (apparently it clamps them to a max of 400dpi). It works at screen res only.
WM_INPUT goes to the raw hid level, gives you mouse data at full precision, and other fun stuff. The code is harder and a lot longer though (but still less code than directinput mouse).
Here's some MSDN info on 3 ways of reading the mouse: http://msdn.microsoft.com/en-us/library ... S.85).aspx
(I've just spent the last hour or so playing with it).
WM_MOUSE is good for simple cursor stuff, but it can't handle high precision mice (apparently it clamps them to a max of 400dpi). It works at screen res only.
WM_INPUT goes to the raw hid level, gives you mouse data at full precision, and other fun stuff. The code is harder and a lot longer though (but still less code than directinput mouse).
Here's some MSDN info on 3 ways of reading the mouse: http://msdn.microsoft.com/en-us/library ... S.85).aspx
-
- Goblin
- Posts: 264
- Joined: Thu Aug 21, 2008 4:48 pm
Re: Using mouse via WinAPI?
What's wrong with IOS?
-
- Halfling
- Posts: 89
- Joined: Thu Apr 22, 2004 11:22 am
- x 1
Re: Using mouse via WinAPI?
Yes that is I wondered: entry point for my callback message processing func and where to put dispatchmessage etc. stuff.xavier wrote:You process them the same as you do for any other Win32 application. The problem you will run into with Ogre, is that the Win32 message dispatching is done in an internal class (WindowEventUtilities) so you'll probably want to make your own Win32 window and embed the Ogre render window in that, so that you have complete control over the message processing. Note, however, what sorts of things the Ogre code does in various scenarios, because you'll need to duplicate it.igorvlassov wrote:Sorry for late reply.xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Classical WM_MOUSE* Windows messages processing.
Of course, you can always subclass the window class and call the Ogre WndProc when yours is done.
-
- Halfling
- Posts: 89
- Joined: Thu Apr 22, 2004 11:22 am
- x 1
Re: Using mouse via WinAPI?
I'm creating hunting game for specialized input equipment (laser riffle). I know it work like mouse but it change cursor position when shot only. As I know older games used windows mouse processing system and all was OK. I created 2 games using old 3d engine. It handled mouse processing by itself and I have a lot of troubles to make it work correctly. The problem also that I haven't direct access to riffle. So I can try to use IOS but I'm afraid to get new problems with.Azgur wrote:What's wrong with IOS?
-
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 535
Re: Using mouse via WinAPI?
I just wrote some code to intercept messages before the ogre winproc about an hour ago. Here's what I did:Yes that is I wondered: entry point for my callback message processing func and where to put dispatchmessage etc. stuff.
(Note: this was part of a quick hacked together test for several random things I'm working on, so ignore crappiness)
Code: Select all
// A global to store ogre's winproc.
// I could just use WindowEventUtilities::_WndProc directly, but this way preserves chaining in case something else did this first.
WNDPROC g_ogreWinProc = NULL;
// Your winproc code, which calls ogre's one when finished.
LRESULT APIENTRY SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
// handle your WM_**** stuff here
}
return CallWindowProc(g_ogreWinProc, hwnd, uMsg, wParam, lParam);
}
// insert this code somewhere in your initialisation:
HWND hwnd;
m_window->getCustomAttribute("WINDOW", (void*)&hwnd);
g_ogreWinProc = (WNDPROC) SetWindowLong(hwnd, GWL_WNDPROC, (LONG) SubclassProc);
-
- Halfling
- Posts: 89
- Joined: Thu Apr 22, 2004 11:22 am
- x 1
Re: Using mouse via WinAPI?
Wow, Kojack,
thanks a lot!
Going to play with your code!!!
thanks a lot!
Going to play with your code!!!
-
- OGRE Community Helper
- Posts: 767
- Joined: Wed Oct 10, 2007 2:36 pm
- Location: Germany
- x 39
Re: Using mouse via WinAPI?
xavier wrote:You process them the same as you do for any other Win32 application. The problem you will run into with Ogre, is that the Win32 message dispatching is done in an internal class (WindowEventUtilities) so you'll probably want to make your own Win32 window and embed the Ogre render window in that, so that you have complete control over the message processing. Note, however, what sorts of things the Ogre code does in various scenarios, because you'll need to duplicate it.igorvlassov wrote:Sorry for late reply.xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Classical WM_MOUSE* Windows messages processing.
Of course, you can always subclass the window class and call the Ogre WndProc when yours is done.
I don't like quotes of quotes of quotes ...igorvlassov wrote:Yes that is I wondered: entry point for my callback message processing func and where to put dispatchmessage etc. stuff.
Please don't use quotes if not needed.
If you use quotes, please use only the related part of text
@igorvlassov
Maybe you can edit your post end remove the quotes?
This would be nice for overview.
Help to add information to the wiki. Also tiny edits will let it grow ...
Add your country to your profile ... it's interesting to know from where of the world you are.
Add your country to your profile ... it's interesting to know from where of the world you are.
-
- OGRE Community Helper
- Posts: 767
- Joined: Wed Oct 10, 2007 2:36 pm
- Location: Germany
- x 39
Re: Using mouse via WinAPI?
Nice, maybe this we can add it to the wiki.Kojack wrote:I just wrote some code
By the way - what is the (dis)advantage to use OIS instead?
I did not understand.
http://www.ogre3d.org/wiki/index.php/OIS
Help to add information to the wiki. Also tiny edits will let it grow ...
Add your country to your profile ... it's interesting to know from where of the world you are.
Add your country to your profile ... it's interesting to know from where of the world you are.
-
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 535
Re: Using mouse via WinAPI?
OIS uses direct input for mouse and keyboard handling (they are planning on changing that sometime). Microsoft recommend not to do that because it is less efficient.
When you tell directinput to read the keyboard and mouse, it spawns a thread that sits there reading WM_INPUT to get mouse and keyboard events. So they say it's better to just read WM_INPUT yourself, especially since it's smaller and easier code than directinput.
Also, directinput is incapable of distinguishing between multiple mice and keyboards, they are all merged together into just 2 system object, whereas WM_INPUT gives you an id number for each device, so you could have your game fully support multiple devices.
Of course that's mostly only of interest to people who don't mind writing their own input library. For most people who don't have specific requirements like multiple mice and keyboards, OIS is awesome.
When you tell directinput to read the keyboard and mouse, it spawns a thread that sits there reading WM_INPUT to get mouse and keyboard events. So they say it's better to just read WM_INPUT yourself, especially since it's smaller and easier code than directinput.
Also, directinput is incapable of distinguishing between multiple mice and keyboards, they are all merged together into just 2 system object, whereas WM_INPUT gives you an id number for each device, so you could have your game fully support multiple devices.
Of course that's mostly only of interest to people who don't mind writing their own input library. For most people who don't have specific requirements like multiple mice and keyboards, OIS is awesome.
-
- OGRE Community Helper
- Posts: 767
- Joined: Wed Oct 10, 2007 2:36 pm
- Location: Germany
- x 39
Re: Using mouse via WinAPI?
Thanks
I added a link to your code with note to the OIS page of wiki.
I added a link to your code with note to the OIS page of wiki.
Help to add information to the wiki. Also tiny edits will let it grow ...
Add your country to your profile ... it's interesting to know from where of the world you are.
Add your country to your profile ... it's interesting to know from where of the world you are.
-
- Gold Sponsor
- Posts: 1894
- Joined: Sun Mar 08, 2009 5:25 am
- x 116
Re: Using mouse via WinAPI?
Apologies for the thread necromancy, I just wanted to say Kojack's above code for intercepting and processing windows messages is gold. It's just what I needed for a windows program I'm adapting to use Ogre. I'd never have been able to come up with that, so thanks!
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.
-
- Gnoblar
- Posts: 9
- Joined: Thu Feb 24, 2011 4:03 pm
- x 1
Re: Using mouse via WinAPI?
I put this code to my Sourcecode, but I get an error:Kojack wrote:Yes that is I wondered: entry point for my callback message processing func and where to put dispatchmessage etc. stuff.
I just wrote some code to intercept messages before the ogre winproc about an hour ago. Here's what I did:
(Note: this was part of a quick hacked together test for several random things I'm working on, so ignore crappiness)
Now you get to handle your stuff and ogre still handles stuff like window move events, etc. At least it does for me so far.Code: Select all
// A global to store ogre's winproc. // I could just use WindowEventUtilities::_WndProc directly, but this way preserves chaining in case something else did this first. WNDPROC g_ogreWinProc = NULL; // Your winproc code, which calls ogre's one when finished. LRESULT APIENTRY SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { // handle your WM_**** stuff here } return CallWindowProc(g_ogreWinProc, hwnd, uMsg, wParam, lParam); } // insert this code somewhere in your initialisation: HWND hwnd; m_window->getCustomAttribute("WINDOW", (void*)&hwnd); g_ogreWinProc = (WNDPROC) SetWindowLong(hwnd, GWL_WNDPROC, (LONG) SubclassProc);
in this line:\Escape_Main.cpp|383|error: invalid use of member (did you forget the '&' ?)|
Code: Select all
ogreWndProc = (WNDPROC) SetWindowLongA(hwnd, GWL_WNDPROC,(LONG) EscapeWndProc);
I dont know, what my compiler wants to tell me
-
- Gnoblar
- Posts: 9
- Joined: Thu Feb 24, 2011 4:03 pm
- x 1
Re: Using mouse via WinAPI?
Cant remember now.
It was long ago since i worked on my program but i think i found a different solution
It was long ago since i worked on my program but i think i found a different solution
-
- Bronze Sponsor
- Posts: 53
- Joined: Wed Mar 25, 2015 10:01 pm
Re: Using mouse via WinAPI?
Thanks for that Code SNippet Kojak! I am porting a game from d3D to Ogre and was having a helluva time getting the winproc to fire. Many Thanks