Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Scancode to ASCII

Author
Message
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 21st Jun 2008 05:10
I'm currently working on a function that will take a scancode as an argument and return a char for it. The non-alphanumeric keys will return their name, such as the End key will return "End".

If you can do any models for FW, reply to the FleetWars thread.

Click here!
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:14
sounds good. probably a cool little widget to put in our toolboxes, eh?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Jun 2008 05:32
Was that a question?

All it takes is a table of (char *) initialized to the appropriate text in order:



The tedium is in aligning the appropriate text with the index that represents the scan code number;

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:38
does that mean there aren't any gaps in the scancode spectrum?
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 21st Jun 2008 05:39 Edited at: 21st Jun 2008 05:39
Exactly, Lilith. I found that if you add 64, you get what you need... in uppercase. If you need lowercase, add 96.

If you can do any models for FW, reply to the FleetWars thread.

Click here!
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Jun 2008 05:50 Edited at: 21st Jun 2008 05:50
Quote: "does that mean there aren't any gaps in the scancode spectrum"


Not necessarily. But with any gaps, as with scancode 0, you just specify an empty string.

Or you could make a massive switch/case statement out of it.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:50 Edited at: 21st Jun 2008 05:51
i see.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Jun 2008 06:04
Mind you, almost anything that returns a scan code or translates one to ascii is going to take up some room. The other downside of the approach I presented is that the scan code table is inside the function, which means that it gets put on the stack every time the function is called. The way around this is to declare the array as a static entity so it gets built in the data area once and won't be rebuilt on each function call.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 06:08 Edited at: 21st Jun 2008 06:08
so:

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Jun 2008 06:14
Yup!

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 06:16
i usually declare tables like that globally, but for the sake of encapsulation in this function, your method is perfect.

is encapsulation the right word?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Jun 2008 06:27
Pretty much. I prefer not to declare anything globally if I can avoid it. It makes things a little bit easier to copy over to other code if I need it.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 22nd Jun 2008 12:52
Sorry for my ignorance but can anyone tell me why one would want to convert from scancode towards a character ?

I can see the benefit of going the opposite way from a character to a scancode.
MACRO
21
Years of Service
User Offline
Joined: 10th Jun 2003
Location:
Posted: 22nd Jun 2008 18:58
This sounds to me like the perfect place for a singleton class.

That way you would keep the encapsulation of data and behaviour and still have access to the functionality throughout the global scope of your code. It would also ensure that only one set of memory is used for the mapping array.

On another thought you may find an stl map useful for the mapping of int scan-code to char* value. That way you still get fast indexing but don't have to worry about gaps in scan-codes and only have to map the specific codes you are interested in.

Just some thoughts

Macro

Login to post a reply

Server time is: 2024-11-20 15:26:31
Your offset time is: 2024-11-20 15:26:31