Disko Forum logo Login  |  Register  |  Lost Password
Re:How do I catch user inputs?

andre
Posts: 35
graphgraph

How do I catch user inputs? 4 Years, 9 Months ago  
Hello,

I have a beginner level question related to the MMSInputManager.

My goal is to be able to catch user inputs from keyboard and take the appropriate action. For example, let's say I want to print a message on the shell each time the user presses the ESCAPE key.

Here is what I am trying to do, but when I run the application I get a segmentation fault:

Code:

#include <mms.h> int main(int argc, char *argv[]) { MMSInputManager im("./inputmap.xml", "mymanager"); im.addDevice(MMS_INPUT_KEYBOARD, 1); MMSInputSubscription insub(MMSKEY_ESCAPE); insub.registerMe(); im.addSubscription(&insub); im.startListen(); pause(); return 0; }
Should I always use mmsInit()? If so, how can I then access the user inputs? As you may see, I am still trying to understand how some of the pieces stick together within the disko framework. Therefore, I would really appreciate some help here, since I honestly could not get the picture from the API reference page. Thanks in advance. Regards, André
 
  The administrator has disabled public write access.
Re:How do I catch user inputs?

andre
Posts: 35
graphgraph

Re:How do I catch user inputs? 4 Years, 9 Months ago  
Can anyone help me with this please?

Thanks,
André
 
  The administrator has disabled public write access.
Re:How do I catch user inputs?

René
Admin
Posts: 11
graphgraph

Re:How do I catch user inputs? 4 Years, 9 Months ago  
Hi André!

First I have to say that you have to use mmsInit().

The easiest way to achieve your goal is to implement an onHandleInput method and connect it with
a window:

Code:

MyClass::MyClass() { this->myWin = new MMSRootWindow( "", "100%", "100%", MMSALIGNMENT_CENTER); this->myWin->onHandleInput->connect(sigc::mem_fun(this, &MyClass::onHandleInput)); } /* should return true if you handled the event, false otherwise */ bool MyClass::onHandleInput(MMSWindow *window, MMSInputEvent *input) { if(window != this->myWin || input->type != MMSINPUTEVENTTYPE_KEYPRESS) { return false; } switch(input->key) { case MMSKEY_SPACE: printf("user pressed space \n"); break; default: return false; } return true; }
The input subscription is used if you don't want the gui to get the event and connect it directly to a callback function. best regards, René
 
  The administrator has disabled public write access.
Re:How do I catch user inputs?

andre
Admin
Posts: 35
graphgraph

Re:How do I catch user inputs? 4 Years, 9 Months ago  
Hello René.

Thank you very much for your help!

I followed your instructions and was able do what I was trying to.

Although I have my problem solved for now, I would like to take the opportunity to ask another question about this topic:

I realized that in your suggested approach, the user actions stay "attached" to the currently displayed window. But what if I want, for example, to exit the application whenever the user presses the e key, regardless of the currently shown window? I mean, is there any "master" callback function that I can customize?

Thanks & regards,
André
 
  The administrator has disabled public write access.
Re:How do I catch user inputs?

andre
Admin
Posts: 35
graphgraph

Re:How do I catch user inputs? 4 Years, 9 Months ago  
Please ignore my last question.

This is now clear in the new tutorials

Regards,
André
 
  The administrator has disabled public write access.
Powered by FireBoard
get the latest posts directly to your desktop