• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Frahm

cannot receive WM_INPUT_DEVICE_CHANGE message after registered with RIDEV_DEVNOTIFY

9 posts in this topic

Hey, this is my first post, and I have some trouble when implementing my input framework for my game. I want to get notified whenever a keyboard is attached for detached from the computer, but I couldn't get it done.

Here is the relevant codes:

void Input::registerKeyboards() {
  RAWINPUTDEVICE rid[1];
  rid[0].usUsagePage = 0x01;
  rid[0].usUsage = 0x06;
  rid[0].dwFlags = RIDEV_DEVNOTIFY;
  rid[0].hwndTarget = 0;
  if(RegisterRawInputDevices(rid, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
    DebugTrace();
  }
}

 and the message loop

  MSG msg;
  while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0) {
    switch(msg.message) {
      case WM_INPUT:
        input_.onKeyEvent(msg.lParam);
        break;
      case WM_INPUT_DEVICE_CHANGE:
        input_.onDeviceChanges(msg.wParam, msg.lParam);
        break;
      case WM_QUIT:
        this->exit_code_ = msg.wParam;
        return false;
      default:
        DispatchMessage(&msg);
    }
  }

I can receive all the WM_INPUT message, but no WM_INPUT_DEVICE_CHANGE.

There must be something I missed, any suggestions would be appreciated.

0

Share this post


Link to post
Share on other sites

Why in heaven to you process messages in your message loop?

 

You really should only handle messages (beside WM_QUIT) in your window proc. DispatchMessage may actually create new messages while dispatching that will never even appear in your loop.

 

 

Second line on MSDN for WM_INPUT_DEVICE_CHANGE:

 

Sent to the window that registered to receive raw input.

A window receives this message through its WindowProc function.

Edited by Endurion
0

Share this post


Link to post
Share on other sites

Yes, you need to know on Windows there are 2 ways to take a message to you.

SendMessage directly calls the window procedure you gave on window creation when its used.

PostMessage just puts it in the message queue where you can retrieve it with GetMessage or PeekMessage, then you can feed it to TranslateMessage if you want WM_CHAR and similar messages for text input to be generated from keyboard messages and then you call DispatchMessage which checks what window the message belongs to and calls the window procedure for that window.

0

Share this post


Link to post
Share on other sites

Thanks for answering my question.

Why in heaven to you process messages in your message loop?

 

You really should only handle messages (beside WM_QUIT) in your window proc. DispatchMessage may actually create new messages while dispatching that will never even appear in your loop.

 

 

Second line on MSDN for WM_INPUT_DEVICE_CHANGE:

 

Sent to the window that registered to receive raw input.

A window receives this message through its WindowProc function.

 

The reason that I process input messages inside the message loop is to avoid introducing another global variable. Yes, I have tried catching the WM_INPUT_DEVICE_CHANGE message inside the WndProc, and it failed. "Sent to the window that registered to receive raw input", does it mean that I must specify a single window handle to catching this message?

void Input::registerKeyboards(HWND handle) {
  RAWINPUTDEVICE rid[1];
  rid[0].usUsagePage = 0x01;
  rid[0].usUsage = 0x06;
  rid[0].dwFlags = RIDEV_DEVNOTIFY;
  rid[0].hwndTarget = handle;
  if(RegisterRawInputDevices(rid, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
    DebugTrace();
  }
}

this really works well, but I have more than one window, and I need the "inputs following the focus" feature. is there any way to work around this?

 

Yes, you need to know on Windows there are 2 ways to take a message to you.

SendMessage directly calls the window procedure you gave on window creation when its used.

PostMessage just puts it in the message queue where you can retrieve it with GetMessage or PeekMessage, then you can feed it to TranslateMessage if you want WM_CHAR and similar messages for text input to be generated from keyboard messages and then you call DispatchMessage which checks what window the message belongs to and calls the window procedure for that window.

Thanks, you mean that message might comes from a call to SendMessage, it sounds resonable, but after I tried this:

LRESULT CALLBACK WndProc(HWND handle,
                         UINT message,
                         WPARAM w_param,
                         LPARAM l_param) {
  if(message == WM_NCCREATE) {
    SetWindowLongPtr(handle, GWLP_USERDATA, 
    (LONG_PTR)(((LPCREATESTRUCT)l_param)->lpCreateParams));
    //let it propagate
  }
  
  if(message == WM_INPUT_DEVICE_CHANGE) {
    OutputDebugString(L"bingo\n");
  }

  //....

  return DefWindowProc(handle, message, w_param, l_param);
}

it didn't output "bingo" in my output window. I didn't call TranslateMessage since I don't want to process WM_CHAR.

Edited by Frahm
0

Share this post


Link to post
Share on other sites

Did you use the WndProcs HWND as the registered hwndTarget?

no, I set the hwndTarget as 0 since I have more than one window that needs keyboard inputs, and I don't want to restrict the inputs to one window.

0

Share this post


Link to post
Share on other sites

/offtopic

 

Sorry for intruding, but I couldn't help noticing - how does this thread have over 14k views? blink.png

0

Share this post


Link to post
Share on other sites
You could have a message only window that receives all raw input (using RIDEV_INPUTSINK) and passes it on to the other windows.
0

Share this post


Link to post
Share on other sites

/offtopic

 

Sorry for intruding, but I couldn't help noticing - how does this thread have over 14k views? blink.png

Even me doubt about it, but I found that this thread has good rankings when searching with these keywords: "WM_INPUT_DEVICE_CHANGE",  "RIDEV_DEVNOTIFY".

Edited by Frahm
0

Share this post


Link to post
Share on other sites

You could have a message only window that receives all raw input (using RIDEV_INPUTSINK) and passes it on to the other windows.

nice, it works.

 

Thank you all, guys.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0