HTML Codes

I am trying to store the HTML codes for different characters in an array, but I am not sure how to do this, so that when using the keybd_event it can be plugged in.

If you try to do it with a string for storing the HTML code, you get this error.
error C2664: 'keybd_event' : cannot convert parameter 1 from 'const std::string' to 'BYTE'


The segment of code that I am talking about.
1
2
3
string HTML[1];
HTML[0] = "&#65"; //A
keybd_event(HTML[0], 0, 0, 0);


I could do it in a very long if/else statement, but this would be much easier to call and get data from, and take up less space.
I'm not sure what the keybd_event function does, but it evidentally expects a BYTE as its first argument. Generally a BYTE is typedeffed to an unsigned char or something similar.

However, you are passing the first element of an array of strings, specifically the string "&#65".

Please don't confuse HTML code and C++ code. You are writing C++ code that reads or writes HTML code. In this regard "&#65" is an ascii string which is interpretted by HTML as "A", but is interpretted in C++ as "&#65". The "A" that HTML sees is stored in C++ as a BYTE with the value 'A'.

You need a translation function to go from the HTML string to the BYTE that it represents, something like:

BYTE translateHtmlToByte(const std::string& htmlString);

This translation function could contain a very long if/else statement (as you suggested), or you could pre-populate some data structure (like a std::map<std::string, BYTE>) and your translation function would read values from that. Pre-population could be done by reading a configuration file if you wanted to so more and more HTML codes can be added in after you get the guts of your program working.

With the translation function, you code example would change to something like:

1
2
3
string HTML[1];
HTML[0] = "&#65"; //A
keybd_event(translateHtmlToByte(HTML[0]), 0, 0, 0);

Topic archived. No new replies allowed.