Is it possible to obscure or eliminate PS/2 scan codes?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
MilkyGirl
Posts: 10
Joined: Fri Mar 01, 2013 3:10 pm

Is it possible to obscure or eliminate PS/2 scan codes?

Post by MilkyGirl »

I am writing a PS/2 keyboard driver now, and I notice that most OSes seem to map scan codes to ASCII equivalents used in writing.

However, I'd like to re-map and assign certain bytes from the scan codes to different symbols to appear on the console.

For example, I'd like to press "6", but want "3" to come out on the screen(Not that it makes sense, but that's for the example).

What I want to do is map certain scan code bytes sent from the PS/2 serial interface of the keyboard, change their assigned scan code meanings, and re-map them to different values.

EXAMPLE:

Say I write a game that will run on my text-based kernel (ASCII game, if you will), and in this game I want to press "SPACEBAR", which should be 0x39, but I want the hex equivalent to assign its scan code to "P", which is 0x19, and then map the value to its appropriateness for the game's state.
Last edited by MilkyGirl on Fri Mar 08, 2013 3:10 pm, edited 2 times in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Is it possible to obscure or eliminate PS/2 scan codes?

Post by Combuster »

It's called a keyboard layout. :wink:

The numbers you get from the PS/2 controller correspond to physical /locations/ on the keyboard, there's no character info involved.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
MilkyGirl
Posts: 10
Joined: Fri Mar 01, 2013 3:10 pm

Re: Is it possible to obscure or eliminate PS/2 scan codes?

Post by MilkyGirl »

I know that, but if you could please re-read my question after I edited above, could you then re-edit or reply as necessary to fill my question?

I want to re-map scan codes from one key to another, and then use that value input as necessary.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Is it possible to obscure or eliminate PS/2 scan codes?

Post by Combuster »

Either you can't think or you can't talk. Pick one.

The answer I posted is still valid given the question.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Is it possible to obscure or eliminate PS/2 scan codes?

Post by iansjack »

If I understand you correctly, you want the keys to produce one value usually (the normal value), but produce different values within a particular program. I don't think this is an OS issue; can't your program do the remapping, translating characters as it receives them?
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Is it possible to obscure or eliminate PS/2 scan codes?

Post by Mikemk »

What are you trying to do? Map the scan codes to a specific character, then map that character to a different character? That doesn't make much sense...
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
kohlrak
Posts: 18
Joined: Mon Mar 04, 2013 1:54 am

Re: Is it possible to obscure or eliminate PS/2 scan codes?

Post by kohlrak »

AFAIK, you can't remap the scancodes. The scancodes usually translate to ASCII, but not all do, nor do they have to. The fact that they do convert easy is for convenience. If you want to make them mean something else, there's nothing to stop you from making a replace table or something (make a table of 256 bytes and use the scancode as an offset into the table). Doing that, all you have to do is set each byte in the table to whatever you want it to be.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Is it possible to obscure or eliminate PS/2 scan codes?

Post by egos »

Yes, in first stage my keyboard driver only posts event identifier, virtual key code and some flags:
I wrote:Even more generalized way is to use event queue for foreground process. For keyboard I use KEYDOWN and KEYUP events with following parameters: event identifier (dword), virtual key scancode (dword), control key flags (dword: low byte - left, next byte - right), keyboard indicator flags (dword).
When application recieves event package it can translate the package by self or pass this package and required key map selector back to the driver.
If you have seen bad English in my words, tell me what's wrong, please.
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: Is it possible to obscure or eliminate PS/2 scan codes?

Post by rdos »

You generally have some type of table per national keyboard layout that translates scan codes into something OS-specific. Translating to pure ASCII is not a good idea, unless your only aim is text-mode, as GUIs require more specific key information than just ASCII-code. If I did this from scratch today, I'd study the USB HID key definition, and unicode, and make up some new translation using a unicode/HID mixture.
Post Reply