1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C variables in SimConnect_MapClientEventToSimEvent()

Discussion in 'SimConnect' started by TYC4496, 6/12/10.

  1. TYC4496

    TYC4496

    Joined:
    9/11/10
    Messages:
    28
    Country:
    france
    Hi All,

    I would like to map 0,1,..9 keystroke in a Simconnect application. Although the following code works :

    Code:
    hr = SimConnect_MapClientEventToSimEvent(NewSimConnect, EVENT_0);
    hr = SimConnect_MapInputEventToClientEvent(NewSimConnect, INPUT_NUM, "0", EVENT_0);
    hr = SimConnect_AddClientEventToNotificationGroup(NewSimConnect, GROUP_NUM, EVENT_0);
    //
    hr = SimConnect_MapClientEventToSimEvent(NewSimConnect, EVENT_1);
    hr = SimConnect_MapInputEventToClientEvent(NewSimConnect, INPUT_NUM, "1", EVENT_1);
    hr = SimConnect_AddClientEventToNotificationGroup(NewSimConnect, GROUP_NUM, EVENT_1);
    //
    and so on...
    
    I was thinking to do something more concise in the following way :

    Code:
    char* num = (char*)malloc(4 * sizeof(char));
    char* eve = (char*)malloc(8 * sizeof(char));
    for(int n=0; n<=9; n++) {
    	sprintf(num, "\"%1d\"", n);
    	sprintf(eve, "EVENT_%1d", n);
    
            hr = SimConnect_MapClientEventToSimEvent(NewSimConnect, eve);
            hr = SimConnect_MapInputEventToClientEvent(NewSimConnect, INPUT_NUM, num, eve);
            hr = SimConnect_AddClientEventToNotificationGroup(NewSimConnect, GROUP_NUM, eve);
    	}
    
    where num and eve will be the string "0", EVENT_O ; "1", EVENT_1 ; and so on...

    However it doesn't work because num and eve are not replace by there values in the SimConnect arguments....

    Does anybody know if it's possible to do it the way I was thinking ?

    Thanks.
  2. beatle

    beatle

    Joined:
    28/9/06
    Messages:
    324
    Country:
    us-virginia
    The event code has to be an int, not a string, so the code for the eve var is incorrect. Instead you would want something like:

    int eve_code = (int)EVENT_0 + n;
  3. TYC4496

    TYC4496

    Joined:
    9/11/10
    Messages:
    28
    Country:
    france
    Hi Tim,

    Thanks. I will give it a try ;)
  4. TYC4496

    TYC4496

    Joined:
    9/11/10
    Messages:
    28
    Country:
    france
    Hi Tim,

    Thanks it works (with the additional change sprintf(num, "%1d", n) because num is already a string no need of the \").

Share This Page