string to int to BYTE?

Hey there!
Right now im creating a program that use xbox inputs and then send out keyboard functions using sendInput();

It works fine, but now im creating a system wich lets the user of the program
change the settings in a textfile. Wich will then change what the controllers bindings are.

example, if settings.txt says:
Y=button(0xIE)

i want the program to know that when xbox button Y is pressed, execute a sendInput function to the Key: A (0xIE).

The problem is that the virtual keycode (0xIE) i take from the settings.txt is stored as a string (lets say it is stored in string Y_event)and input.ki.wScan has to be of type BYTE.
i made a function wich changes string into int. (because input.ki.wScan seems to be fine getting a int?)
1
2
3
4
5
6
7
8
9
int stringToInt(string insert)
{
	char back[20];
	for(unsigned int e=0;e < insert.length();e++)
	{
		back[e]=insert[e];
	}
	return atoi(back);
}

but when i run the code nothing happends...

In the code i have a function wich executes the keypress:
void pressbutton(int key, int time)

when i send in the converted string it doesn't work
but when i send in: (0xIE) it works.
1
2
pressButton(stringToInt(Y_Event),50) // doesn't work
pressButton(0xIE,50)                 // works 

I apologize if this got a little messy, hope your understand what i mean!
If you don't undestood what i need help with, focus on the last part that i wrote.
I asked my friend and he linked me this:
http://pastebin.com/yFphFBEB

my convertion didn't work but that one did:

1
2
3
4
5
6
7
8
    int stringToInt(string insert)
    {
            int tmp;
            std::stringstream ss;
            ss << std::hex << insert;
            ss >> tmp;
            return tmp;
    }
I've personally enjoyed using https://github.com/cppformat/cppformat for various conversions and a std::ss replacement.
You might consider strtol also.
http://www.cplusplus.com/reference/cstdlib/strtol/
Topic archived. No new replies allowed.