Jump to content
  • Advertisement
Sign in to follow this  
BladeStone

Noob question about Wide Character Set

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

On my keyboard I've got four stand alone arrows, which is (up, down, right, left) Ascii characters 273, 274, 275, 276. This is beyond 256, therefore those character are wide characters. I've over come this problems by double recieving the command. If the first character is 224, then catch the next one. If it's H it's up, P it's down, M it's right, and K it's left. Ok so people cringe at that because a little fish character is left on the command line (which is 224 under the terminal character set ... standard dos), and catching two characters on a single keystroke bugs them. (Them: being people who might hire me.) Most of the conversations about std::wout and stuff is over my head. How would I work with wide characters. Is there any good documentation on it? ------------ Second noob question, what is 0x06ff? Where do I learn about this and does it have anything to do with ctrl-c style of command? If so, where's the document which talks about it, neither of my books says much about wide or the 0xffff. Thank you in advance here.

Share this post


Link to post
Share on other sites
Advertisement
Basically for all the C++ Standard Library classes that use strings there are two versions: a version that uses strings of single-byte characters, and a version that uses double-byte (wide) characters. Single-byte characters use the type "char", while wide characters use the type "wchar_t". The convention for these is that wide-character versions are named the same, but with a "w" in front. Some of the common classes used are std::wstring, std::wifstream, std::wcout, and std::wcin.

If you want to use those classes so that you work with wide characters, just go ahead and use them. They work exactly the same as the single-character versions. The only difference is that if you need to use a string literal with them, you need to use a wide-character string literal. Like this:

std::wstring wStr = L"Wide-character string!";


As for your second question, I'm not really sure what you're asking...are you asking what character that value corresponds to?

Share this post


Link to post
Share on other sites
Thank you for the information on the Wide Character Set.

As for the second question, I've seen people refer to values and characters as zero, little x, and a cobination of letter and number (most likely hexadesmil). I've see address for pointer that look like that as well, but longer on the right side of the little x.

I've covered quite a few pages of C/C++ books and there is no mention of it, yet I've seen code with it in it.

char bob = 0xffff;

I'm guessing it's a memmory address of something.

Share this post


Link to post
Share on other sites
The notation 0x is for writing hexadecimal numbers. For example, the following are true

0x1 == 1
0xA == 10
0xF == 15
0x10 == 16
0xFF == 255

It's not necessarily a memory address; it's used because it's convenient for writing large numbers as well as for values which will later be combined using AND, OR, and NOT.

Share this post


Link to post
Share on other sites
I use hexadecimal mainly because it's much easier than decimal numbers to visualize the binary equivalent, since each digit in hexadecimal represents 4 bits.

Writing values in binary is much too big of a pain.

If I don't necessarily care about the binary equivalent of a number I tend to express it in decimal form.

Share this post


Link to post
Share on other sites
Your keyboard stuff doesn't actually have anything to do with wide characters or ASCII. The numbers you're reading aren't characters at all.

When you press a key the keyboard sends a number to the OS telling it what key was pressed. This number is called a "scan code". Somewhere along the line keyboard hardware designers decided that some keys would generate more than one scan code. These special keys are known as "extended keys". Arrow keys are just one example.

Whatever OS/language combo you're using probably knows about all this and is converting scan codes to characters for you when it can. But since arrow keys aren't characters it just gives up and sends you the raw data to handle on your own.

In some ways it's unfortunate this automatic conversion happens at all since it leads to lots and lots of people thinking that keys and characters are basically the same thing when they're really not even close. It only even kind of works if all you care about is English and the standard US qwerty keyboard layout.

Share this post


Link to post
Share on other sites
Following on what Anon Mike said, if you're on Windows, key events are sent in INPUT_RECORDs under its KeyEvent member, of type KEY_EVENT_RECORD. The key event record stored a virtual scan code, a virtual key code (what you'll want to check for a particular key), and among other things a uChar union which stores the key's character value (if you push the U key, chances are it contains 'u'), in ASCII and Unicode (KeyEvent.uChar.AsciiChar will get you the Ascii value). For your arrow keys, you would just want to check if the virtual key code was VK_LEFT, VK_RIGHT, VK_UP, or VK_DOWN, and act accordingly.

That's only if you're on Windows though.. I have no idea how Linux and Mac do it. And a paste of relevant code would probably have helped get you some more exact answers.

Share this post


Link to post
Share on other sites
Twisol, Anon Mike, Colin Jeanne, and MJP:

Wow! That will give me a bit to go research up on. That's all good information I was hoping for. Thank you!

As for how I found out the key number was one of my intro sample codes showed me how to take a keystroke and output it as an intiger. Therefore, the arrow keys gave me numbers and I played with that until things worked. Low tech, yes.

Edit: Oh then I can bring up dos and hold down alt, type in the number, and poof I get the same reaction out of my computer as if I stroke those keys. Like Enter is 13, hold alt, type 13 in the NumLock key pad and then reliece alt. Poof, new command like as if you hit enter. :)

I'll see what I can find with the new information. Thank you

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!