Thread: ps2 keyboard programming

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    1

    ps2 keyboard programming

    hi.
    i'm trying to program my ps2 keyboard in c.
    i want to write the keyboard port (60h) and to for example get the number 3 on the screen.
    i searched on google how to do this, and i know that there is scan code sets (every letter have it's own make code and break code) i tried to send the keyboard port the make code for the number 3 (04h) and than to send the break code (84h) but it didn't worked.
    the scan code set is listed in this link - Scan Codes -- Set 1
    please help me.
    thank's, shachar.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Lemme guess, you're using TurboC on XP ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Salem View Post
    Lemme guess, you're using TurboC on XP ?
    It'll "work," just don't delude yourself in thinking that you're actually reading from a physical port. It's a virtual environment, which means you're NOT actually talking to hardware. Only the OS can do that.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    He really should get into the 21 century for real projects, if he has no reason to stay locked in the past.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Everyone else's comment aside, you can't SEND key codes TO the keybaord controller. Whilst it is not strictly a one-way communication, it is not possible to "feed keypresses" into the keyboard controller.

    I know this because once I wrote code that simulated what the keyboard controller does. On that system, there was a SPECIAL register to write to for feeding stuff into port 60 and 64. And there possibly is such a port in other systems too, but it's normally used by code that handles the USB keyboard when running non-USB capable OS (which is sort of what I was doing in the case where I wrote the code in question, except it was a PS/2 keyboard on a non-PS/2 capable machine).

    And of course, as everyone has pointed out, if you are actually using an operating system released in the last 10 years or so, you can't actually read/write i/o ports from code that isn't a driver. So if you are doing something like reading/writing ports in a Turbo C program, it doesn't ACTUALLY access port 60/64 - it is trapped by Windows and translated to a "check keyboard status" call to Windows (so for example, you can read via port 60 to get a USB keyboard input - because it's not ACTUALLY reading port 60).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  2. Keyboard port using other that a keyboard
    By antoinelac in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2008, 02:46 PM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  4. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM
  5. : Difference between message queue and keyboard buffer...
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 02-21-2002, 03:47 PM