Solved

Dos menus

Posted on 2000-03-23
36
357 Views
Last Modified: 2008-02-20
My real question is really how can i get access to specific keys on the keyboard like the arrows and what now.

if you can provide source that compiles on djgpp all the better this is not for school its just a project i wanted to do.

Thanks allot PLEASE help i tried lots of code but none will compile in djgpp

i need this to make a menu though so i need the tab button as well as enter
0
Comment
Question by:beyonddeath
  • 18
  • 17
36 Comments
 

Author Comment

by:beyonddeath
Comment Utility
Adjusted points from 100 to 375
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
In dos the "extended keys" like the arrows, will return two values.  The first is either 0 or 0x0E.  Then the next character identifies which extended key was typed.

I'll paste in a table of these keys.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
here is the table
*******************
Keyboard Codes           Keyboard Scan Codes etc.

    This tables lists all the keyboard codes that are returned by calls to
    INT 16 functions 0 through 2 (the second and third columns) and 10h
    through 12h (the last column).

    NOTE: The ASCII Code is Contained in the LOW (Right) Byte of the
          Keyboard Scan Codes.

                             83/84-Key[1]  101/102-Key[2]  101/102-Key
                               Standard       Standard       Extended
     Keystroke                 Function     Function[3]    Function[4]
     Esc                        01/1B           same           same
     1                          02/31           same           same
     2                          03/32           same           same
     3                          04/33           same           same
     4                          05/34           same           same
     5                          06/35           same           same
     6                          07/36           same           same
     7                          08/37           same           same
     8                          09/38           same           same
     9                          0A/39           same           same
     0                          0B/30           same           same
     -                          0C/2D           same           same
     =                          0D/3D           same           same
     Backspace                  0E/08           same           same
     Tab                        0F/09           same           same
     q                          10/71           same           same
     w                          11/77           same           same
     e                          12/65           same           same
     r                          13/72           same           same
     t                          14/74           same           same
     y                          15/79           same           same
     u                          16/75           same           same
     i                          17/69           same           same
     o                          18/6F           same           same
     p                          19/70           same           same
     [                          1A/5B           same           same
     ]                          1B/5D           same           same
     Enter                      1C/0D           same           same
     Ctrl                         **             **             **
     a                          1E/61           same           same
     s                          1F/73           same           same
     d                          20/64           same           same
     f                          21/66           same           same
     g                          22/67           same           same
     h                          23/68           same           same
     j                          24/6A           same           same
     k                          25/6B           same           same
     l                          26/6C           same           same
     ;                          27/3B           same           same
     '                          28/27           same           same
     `                          29/60           same           same
     Shift                        **             **             **
     \                          2B/5C           same           same
     z                          2C/7A           same           same
     x                          2D/78           same           same
     c                          2E/63           same           same
     v                          2F/76           same           same
     b                          30/62           same           same
     n                          31/6E           same           same
     m                          32/6D           same           same
     ,                          33/2C           same           same
     .                          34/2E           same           same
     /                          35/2F           same           same
     Gray *                     37/2A           same           same
     Alt                          **             **             **
     Space                      39/20           same           same
     Caps Lock                    **             **             **
     F1                         3B/00           same           same
     F2                         3C/00           same           same
     F3                         3D/00           same           same
     F4                         3E/00           same           same
     F5                         3F/00           same           same
     F6                         40/00           same           same
     F7                         41/00           same           same
     F8                         42/00           same           same
     F9                         43/00           same           same
     F10                        44/00           same           same
     F11                        no key           --           85/00
     F12                        no key           --           86/00
     Num Lock                     **             **             **
     Scroll Lock                  **             **             **
     White Home                 47/00           same           same
     White Up Arrow             48/00           same           same
     White PgUp                 49/00           same           same
     Gray -                     4A/2D           same           same
     White Left Arrow           4B/00           same           same
     Center Key                   --             --           4C/00
     White Right Arrow          4D/00           same           same
     Gray +                     4E/2B           same           same
     White End                  4F/00           same           same
     White Down Arrow           50/00           same           same
     White PgDn                 51/00           same           same
     White Ins                  52/00           same           same
     White Del                  53/00           same           same
     SysReq                     no key           **             **
     Key 45 [5]                 no key         56/5C           same
     Enter (number keypad)      no key         1C/0D          E0/0D
     Gray /                     no key         35/2F          E0/2F
     PrtSc                      no key           **             **
     Pause                      no key           **             **
     Gray Home                  no key         47/00          47/E0
     Gray Up Arrow              no key         48/00          48/E0
     Gray Page Up               no key         49/00          49/E0
     Gray Left Arrow            no key         4B/00          4B/E0
     Gray Right Arrow           no key         4D/00          4D/E0
     Gray End                   no key         4F/00          4F/E0
     Gray Down Arrow            no key         50/00          50/E0
     Gray Page Down             no key         51/00          51/E0
     Gray Insert                no key         52/00          52/E0
     Gray Delete                no key         53/00          53/E0

     Shift Esc                  01/1B           same           same
     !                          02/21           same           same
     @                          03/40           same           same
     #                          04/23           same           same
     $                          05/24           same           same
     %                          06/25           same           same
     ^                          07/5E          same           same
     &                          08/26           same           same
     * (white)                  09/2A           same           same
     (                          0A/28           same           same
     )                          0B/29           same           same
     _                          0C/5F           same           same
     + (white)                  0D/2B           same           same
     Shift Backspace            0E/08           same           same
     Shift Tab (Backtab)        0F/00           same           same
     Q                          10/51           same           same
     W                          11/57           same           same
     E                          12/45           same           same
     R                          13/52           same           same
     T                          14/54           same           same
     Y                          15/59           same           same
     U                          16/55           same           same
     I                          17/49           same           same
     O                          18/4F           same           same
     P                          19/50           same           same
     {                          1A/7B           same           same
     }                          1B/7D           same           same
     Shift Enter                1C/0D           same           same
     Shift Ctrl                   **             **             **
     A                          1E/41           same           same
     S                          1F/53           same           same
     D                          20/44           same           same
     F                          21/46           same           same
     G                          22/47           same           same
     H                          23/48           same           same
     J                          24/4A           same           same
     K                          25/4B           same           same
     L                          26/4C           same           same
     :                          27/3A           same           same
     "                          28/22           same           same
     ~                          29/7E           same           same
     |                          2B/7C           same           same
     Z                          2C/5A           same           same
     X                          2D/58           same           same
     C                          2E/43           same           same
     V                          2F/56           same           same
     B                          30/42           same           same
     N                          31/4E           same           same
     M                          32/4D           same           same
     <                          33/3C           same           same
     >                          34/3E           same           same
     ?                          35/3F           same           same
     Shift Gray *                 **             **           37/2A
     Shift Alt                    **             **             **
     Shift Space                39/20           same           same
     Shift Caps Lock              **             **             **
     Shift F1                   54/00           same           same
     Shift F2                   55/00           same           same
     Shift F3                   56/00           same           same
     Shift F4                   57/00           same           same
     Shift F5                   58/00           same           same
     Shift F6                   59/00           same           same
     Shift F7                   5A/00           same           same
     Shift F8                   5B/00           same           same
     Shift F9                   5C/00           same           same
     Shift F10                  5D/00           same           same
     Shift F11                  no key           --           87/00
     Shift F12                  no key           --           88/00
     Shift Num Lock               **             **             **
     Shift Scroll Lock            **             **             **
     Shift 7 (number pad)       47/37           same           same
     Shift 8 (number pad)       48/38           same           same
     Shift 9 (number pad)       49/39           same           same
     Shift Gray -               4A/2D           same           same
     Shift 4 (number pad)       4B/34           same           same
     Shift 5 (number pad)       4C/35           same           same
     Shift 6 (number pad)       4D/36           same           same
     Shift Gray +               4E/2B           same           same
     Shift 1 (number pad)       4F/31           same           same
     Shift 2 (number pad)       50/32           same           same
     Shift 3 (number pad)       51/33           same           same
     Shift 0 (number pad)       52/30           same           same
     Shift . (number pad)       53/2E           same           same
     Shift SysReq               no key           **             **
     Shift Key 45 [5]           no key         56/7C           same
     Shift Enter (number pad)   no key         1C/0D          E0/0D
     Shift Gray /               no key         35/2F          E0/2F
     Shift PrtSc                no key           **             **
     Shift Pause                no key           **             **
     Shift Gray Home            no key         47/00          47/E0
     Shift Gray Up Arrow        no key         48/00          48/E0
     Shift Gray Page Up         no key         49/00          49/E0
     Shift Gray Left Arrow      no key         4B/00          4B/E0
     Shift Gray Right Arrow     no key         4D/00          4D/E0
     Shift Gray End             no key         4F/00          4F/E0
     Shift Gray Down Arrow      no key         50/00          50/E0
     Shift Gray Page Down       no key         51/00          51/E0
     Shift Gray Insert          no key         52/00          52/E0
     Shift Gray Delete          no key         53/00          53/E0

     Ctrl Esc                   01/1B           same           same
     Ctrl 1                       --             --             --
     Ctrl 2 (NUL)               03/00           same           same
     Ctrl 3                       --             --             --
     Ctrl 4                       --             --             --
     Ctrl 5                       --             --             --
     Ctrl 6 (RS)                07/1E           same           same
     Ctrl 7                       --             --             --
     Ctrl 8                       --             --             --
     Ctrl 9                       --             --             --
     Ctrl 0                       --             --             --
     Ctrl -                     0C/1F           same           same
     Ctrl =                       --             --             --
     Ctrl Backspace (DEL)       0E/7F           same           same
     Ctrl Tab                     --             --           94/00
     Ctrl q (DC1)               10/11           same           same
     Ctrl w (ETB)               11/17           same           same
     Ctrl e (ENQ)               12/05           same           same
     Ctrl r (DC2)               13/12           same           same
     Ctrl t (DC4)               14/14           same           same
     Ctrl y (EM)                15/19           same           same
     Ctrl u (NAK)               16/15           same           same
     Ctrl i (HT)                17/09           same           same
     Ctrl o (SI)                18/0F           same           same
     Ctrl p (DEL)               19/10           same           same
     Ctrl [ (ESC)               1A/1B           same           same
     Ctrl ] (GS)                1B/1D           same           same
     Ctrl Enter (LF)            1C/0A           same           same
     Ctrl a (SOH)               1E/01           same           same
     Ctrl s (DC3)               1F/13           same           same
     Ctrl d (EOT)               20/04           same           same
     Ctrl f (ACK)               21/06           same           same
     Ctrl g (BEL)               22/07           same           same
     Ctrl h (Backspace)         23/08           same           same
     Ctrl j (LF)                24/0A           same           same
     Ctrl k (VT)                25/0B           same           same
     Ctrl l (OFF)                26/0C           same           same
     Ctrl ;                       --             --             --
     Ctrl '                       --             --             --
     Ctrl `                       --             --             --
     Ctrl Shift                   **             **             **
     Ctrl \ (FSZ)                2B/1C           same           same
     Ctrl z (SUB)               2C/1A           same           same
     Ctrl x (CAN)               2D/18           same           same
     Ctrl c (ETB)               2E/03           same           same
     Ctrl v (SYS)               2F/16           same           same
     Ctrl b (STI)               30/02           same           same
     Ctrl n (SO)                31/0E           same           same
     Ctrl m (CR)                32/0D           same           same
     Ctrl ,                       --             --             --
     Ctrl .                       --             --             --
     Ctrl /                       --             --             --
     Ctrl Gray *                  --             --           96/00
     Ctrl Alt                     **             **             **
     Ctrl Space                 39/20           same           same
     Ctrl Caps Lock               --             --             --
     Ctrl F1                    5E/00           same           same
     Ctrl F2                    5F/00           same           same
     Ctrl F3                    60/00           same           same
     Ctrl F4                    61/00           same           same
     Ctrl F5                    62/00           same           same
     Ctrl F6                    63/00           same           same
     Ctrl F7                    64/00           same           same
     Ctrl F8                    65/00           same           same
     Ctrl F9                    66/00           same           same
     Ctrl F10                   67/00           same           same
     Ctrl F11                   no key           --           89/00
     Ctrl F12                   no key           --           8A/00
     Ctrl Num Lock                --             --             --
     Ctrl Scroll Lock             --             --             --
     Ctrl White Home            77/00           same           same
     Ctrl White Up Arrow          --             --           8D/00
     Ctrl White PgUp            84/00           same           same
     Ctrl Gray -                  --             --           8E/00
     Ctrl White Left Arrow      73/00           same           same
     Ctrl 5 (number pad)          --             --           8F/00
     Ctrl White Right Arrow     74/00           same           same
     Ctrl Gray +                  --             --           90/00
     Ctrl White End             75/00          75/00           same
     Ctrl White Down Arrow        --             --           91/00
     Ctrl White PgDn            76/00           same           same
     Ctrl White Ins               --             --           92/00
     Ctrl White Del               --             --           93/00
     Ctrl SysReq                no key           **             **
     Ctrl Key 45 [5]            no key           --             --
     Ctrl Enter (number pad)    no key         1C/0A          E0/0A
     Ctrl / (number pad)        no key           --           95/00
     Ctrl PrtSc                 no key         72/00           same
     Ctrl Break                 no key         00/00           same
     Ctrl Gray Home             no key         77/00          77/E0
     Ctrl Gray Up Arrow         no key           --           8D/E0
     Ctrl Gray Page Up          no key         84/00          84/E0
     Ctrl Gray Left Arrow       no key         73/00          73/E0
     Ctrl Gray Right Arrow      no key         74/00          74/E0
     Ctrl Gray End              no key         75/00          75/E0
     Ctrl Gray Down Arrow       no key           --           91/E0
     Ctrl Gray Page Down        no key         76/00          76/E0
     Ctrl Gray Insert           no key           --           92/E0
     Ctrl Gray Delete           no key           --           93/E0

     Alt Esc                      --             --           01/00
     Alt 1                      78/00           same           same
     Alt 2                      79/00           same           same
     Alt 3                      7A/00           same           same
     Alt 4                      7B/00           same           same
     Alt 5                      7C/00           same           same
     Alt 6                      7D/00           same           same
     Alt 7                      7E/00           same           same
     Alt 8                      7F/00           same           same
     Alt 9                      80/00           same           same
     Alt 0                      81/00           same           same
     Alt -                      82/00           same           same
     Alt =                      83/00           same           same
     Alt Backspace                --             --           0E/00
     Alt Tab                      --             --           A/00
     Alt q                      10/00           same           same
     Alt w                      11/00           same           same
     Alt e                      12/00           same           same
     Alt r                      13/00           same           same
     Alt t                      14/00           same           same
     Alt y                      15/00           same           same
     Alt u                      16/00           same           same
     Alt i                      17/00           same           same
     Alt o                      18/00           same           same
     Alt p                      19/00           same           same
     Alt [                        --             --           1A/00
     Alt ]                        --             --           1B/00
     Alt Enter                    --             --           1C/00
     Alt Ctrl                     **             **             **
     Alt a                      1E/00           same           same
     Alt s                      1F/00           same           same
     Alt d                      20/00           same           same
     Alt f                      21/00           same           same
     Alt g                      22/00           same           same
     Alt h                      23/00           same           same
     Alt j                      24/00           same           same
     Alt k                      25/00           same           same
     Alt l                      26/00           same           same
     Alt ;                        --             --           27/00
     Alt '                        --             --           28/00
     Alt `                        --             --           29/00
     Alt Shift                    **             **             **
     Alt \                        --             --           2B/00
     Alt z                      2C/00           same           same
     Alt x                      2D/00           same           same
     Alt c                      2E/00           same           same
     Alt v                      2F/00           same           same
     Alt b                      30/00           same           same
     Alt n                      31/00           same           same
     Alt m                      32/00           same           same
     Alt ,                        --             --           33/00
     Alt .                        --             --           34/00
     Alt /                        --             --           35/00
     Alt Gray *                   --             --           37/00
     Alt Space                  39/20           same           same
     Alt Caps Lock                **             **             **
     Alt F1                     68/00           same           same
     Alt F2                     69/00           same           same
     Alt F3                     6A/00           same           same
     Alt F4                     6B/00           same           same
     Alt F5                     6C/00           same           same
     Alt F6                     6D/00           same           same
     Alt F7                     6E/00           same           same
     Alt F8                     6F/00           same           same
     Alt F9                     70/00           same           same
     Alt F10                    71/00           same           same
     Alt F11                    no key           --           8B/00
     Alt F12                    no key           --           8C/00
     Alt Num Lock                 **             **             **
     Alt Scroll Lock              **             **             **
     Alt Gray -                   --             --           4A/00
     Alt Gray +                   --             --           4E/00
     Alt 7 (number pad)           #              #              #
     Alt 8 (number pad)           #              #              #
     Alt 9 (number pad)           #              #              #
     Alt 4 (number pad)           #              #              #
     Alt 5 (number pad)           #              #              #
     Alt 6 (number pad)           #              #              #
     Alt 1 (number pad)           #              #              #
     Alt 2 (number pad)           #              #              #
     Alt 3 (number pad)           #              #              #
     Alt Del                      --             --             --
     Alt SysReq                 no key           **             **
     Alt Key 45 [5]             no key           --             --
     Alt Enter (number pad)     no key           --           A/00
     Alt / (number pad)           --             --           A/00
     Alt PrtSc                  no key           **             **
     Alt Pause                  no key           **             **
     Alt Gray Home              no key           --           97/00
     Alt Gray Up Arrow          no key           --           98/00
     Alt Gray Page Up           no key           --           99/00
     Alt Gray Left Arrow        no key           --           9B/00
     Alt Gray Right Arrow       no key           --           9D/00
     Alt Gray End               no key           --           9F/00
     Alt Gray Down Arrow        no key           --           A/00
     Alt Gray Page Down         no key           --           A/00
     Alt Gray Insert            no key           --           A/00
     Alt Gray Delete            no key           --           A/00

  Footnotes

        [1]   The 83-key and 84-key keyboards are the original PC keyboard
              and the original-layout AT keyboard, respectively.

        [2]   The 101/102-key keyboard is the current IBM standard
              ("Enhanced") keyboard.

        [3]   "Standard Function" refers to Interrupt 16h Services 0, 1,
              and 2.

        [4]   "Extended Function" refers to Interrupt 16h Services 10h,
              11h, and 12h.

        [5]   In the United States, the 101/102-key keyboard is shipped
              with 101 keys. Overseas versions have an additional key
              sandwiched between the left Shift key and the Z key. This
              additional key is identified by IBM (and in this table) as
              "Key 45."

        [**]  Keys and key combinations marked ** are used by the ROM BIOS
              but do not put values into the keyboard buffer.

        [--]  Keys and key combinations marked -- are ignored by the ROM
              BIOS.



 

0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Now in most cases, you can obtain these values by using _getch() or _getche() functions.  These are a non-standard function, so your compiler may not have it.  But if it does, the "normal" characters (letters, digits, symbols) will return their ASCII codes from _getch() or _getche().  But the extended keys will first return a 0x00 or a 0x0E, then the scan code  found in the first column (before the "/") in the table above.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
If you don't have getch() or getche() availalble you should look to see if you have any other non-standard I/O functions that don't line buffer.  (All Standard I/O functions are line-buffered, meaning that the user has to press enter before the information they type is made available to your program.  So to use the right arraow, they woudl have to press the right arrow, then press enter.  You don't want that, so you need non-standard functions that don't buffer until enter is pressed.)

If you can't find any non-standard functions that don't do the line buffering, you will have to use the BIOS keyboard services.   There is service that you can use to test to see if there are keys waiting to be read and another service you can use to read the keys that are waiting.

I'll post descriptions of these.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
*********************************************
To see if a character is available use interupt 16H, service 01h.  Like
   bool CharacterReady = true;
    _asm MOV AH 01H
    INT 16H
    JNZ AROUND
    MOV CharacterReady,0

AROUND:
*********************************************
INT 16h,  01h (1)        Keyboard Status                                  all

    Checks to see if a character is available in the buffer.

       On entry:      AH         01h

       Returns:       Zero       0, if character is available
                                 1, if character is not available
                      AL         ASCII character code (if character is
                                 available)
                      AH         Scan code (if character is available)

  --------------------------------------------------------------------------

       Notes:         If a character is available, the Zero Flag is
                      cleared and AX contains the ASCII value in AL and
                      the scan code in AH. The character is not removed
                      from the buffer. Use Service 00h to remove the
                      character from the buffer. See Service 00h for a
                      complete description of the meaning of AX if a
                      character is available.

                      This service is excellent for clearing the keyboard
                      or allowing a program to be interruptable by a
                      specific key sequence.

                      See Service 11h for an equivalent service that
                      supports the enhanced (101/102-key) keyboard.

0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Opps.  I meant to put an _asm in front of all those lines of assembly there.

Use interupt 16H service 0 to read a key from the keyboard.  (After verifying that one is waiting with serive 01H.)   Like

unsigned char ScanCode;

   _asm MOV AH,0
   _asm INT 16H
   _asm MOV ScanCode,AH

*****************************************
INT 16h,  00h (0)        Keyboard Read                                    all

    Returns the next character in the keyboard buffer; if no character is
    available, this service waits until one is available.

       On entry:      AH         00h

       Returns:       AL         ASCII character code
                      AH         Scan code

  --------------------------------------------------------------------------

       Notes:         The scan codes are the numbers representing the
                      location of the key on the keyboard. As new keys
                      have been added and the keyboard layout rearranged,
                      this numbering scheme has not been consistent with
                      its original purpose.

                      If the character is a special character, then AL
                      will be 0 and the value in AH will be the extended
                      scan code for the key.

                      Use the scan codes to differentiate between keys
                      representing the same ASCII code, such as the plus
                      key across the top of the keyboard and the gray plus
                      key.

                      After the character has been removed from the
                      keyboard buffer, the keyboard buffer start pointer
                      (at 0:041Ah) is increased by 2. If the start pointer
                      is beyond the end of the buffer, the start pointer
                      is reset to the start of the keyboard buffer.

                      If no character is available at the keyboard, then
                      the AT, XT-286, and PC Convertible issue an INT 15h,
                      Service 90h (Device Busy), for the keyboard,
                      informing the operating system that there is a
                      keyboard loop taking place and thereby allowing the
                      operating system to perform another task.

                      After every character is typed, the AT, XT-286, and
                      PC Convertible issue an INT 15h, Service 91h
                      (Interrupt Complete). This allows the operating
                      system to switch back to a task that is waiting for
                      a character at the keyboard.

                      See Service 10h for an equivalent service that
                      supports the enhanced (101/102-key) keyboard.
0
 

Author Comment

by:beyonddeath
Comment Utility
I wanted a source as i dont have a clue what assembly means (im only 14 give me a break)  and i got a source file that has all this but i cant compile it...
cause it was made with an old compiler,
if you do up source for just funtion key or whatnot then the 375 is yours.  Great description of how that all works though.  also how do i get it to round if i want to specify 2 numbers that it should round closest to..

This is what i have:

/*****************************************/
/* Keyboard Interupt Program Source Code */
/*****************************************/
#include "keydef.cpp"
#include <dos.h>

#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif

void interrupt far (*Old_Isr)(__CPPARGS); //Global variable!!!!

void store_keyboard()
{
   Old_Isr = _dos_getvect(9);
}



void restore_keyboard()
{
   _dos_setvect(9, Old_Isr);
}




int raw_key,lastkey; //Must be global variables!!!
int keys[400]; //Must be global
void interrupt far New_Key_Int(__CPPARGS)
{
   int scan,scanx;
   scan=inp(0x60);
   if (scan>0x7F)
   {
       asm {mov ax,scan;
        xor ax,0x80;
        mov scanx,ax;}
       if (keys[scanx]) raw_key--;
       keys[scanx]=0;
   }
   else
   {
      if (!keys[scan]) raw_key++;
      keys[scan]=1;
      lastkey=scan;
   }
   outp(0x20,0x20);
}

void install_new_keyboard()
{
   _dos_setvect(9, New_Key_Int);
}


and the include file:

#define Y         21
#define U         22
#define I         23
#define O         24
#define P         25
#define LSQUAREBRACKET  26
#define RSQUAREBRACKET  27
#define ENTER       28
#define CONTROL     29
#define A         30
#define S         31
#define D         32
#define F         33
#define G         34
#define H         35
#define J         36
#define K         37
#define L         38
#define SEMICOLON   39
#define QUOTE         40
#define TILDE        41
#define L_SHIFT     42
#define BACKSLASH   43
#define Z         44
#define X         45
#define C         46
#define V         47
#define B         48
#define N         49
#define M         50
#define COMMA         51
#define PERIOD         52
#define SLASH         53
#define R_SHIFT     54
#define NUM_STAR        55
#define ALT         56
#define SPACEBAR    57
#define CAPS      58
#define F1          59
#define F2          60
#define F3          61
#define F4          62
#define F5          63
#define F6          64
#define F7          65
#define F8          66
#define F9          67
#define F10         68
#define NUMLOCK     69
#define SCROLLLOCK  70
#define NUM7        71
#define NUM8        72
#define UP          72
#define NUM9        73
#define NUMMINUS        74
#define NUMPLUS        75
#define LEFT        75
#define NUM4        76
#define NUM5        77
#define RIGHT       77
#define NUM6        78
#define NUM1        79
#define NUM2        80
#define DOWN        80
#define NUM3        81
#define NUM0        82
#define DECIMAL     83

#define F11         87
#define F12         88

#define WIN         91

#define WIN2        93
Thanks if you can find why i this doesnt work for me or can provide me with a better solution.  Sorry for the
rejection ;(
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
What exactly do you want to do?

What I see you doing is hooking the keyboard notification interrupt and then trying to read the key information directly from the keyboard.  That is a lot of work and should not be attempted by someone with only a little experience.  (If you don't know what assembly is, you best forget it!)

If you just want to read the keys, there is no need to hook the keybopard or to communicate directly with the keyboard.   You are best of using getch() or getche() if they are available, if not you are best of using the DOS keyboard services as I showed you above.

Is there a reason you are trying to do all that?
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
The following functions should work (if your compiler isn't too out-of date)

bool IsKeyWaiting()
{
   bool CharacterReady = true;

    asm
    {
        MOV AH 01H
        INT 16H
        JNZ AROUND
        MOV CharacterReady,0
AROUND:
    }
    return CharacterReady;
}

char ReadCharacter()
{
   unsigned char ScanCode;
   asm
   {
      MOV AH,0
      INT 16H
      MOV ScanCode,AH
   }
   return ScanCode;
}

But you are better off using getch() (or _getch()) if it is available.
0
 

Expert Comment

by:sunsetyang
Comment Utility
Check you include directory to see whether there is a file named as bios.h,If exists,you can check the header file to see the right function.Sometimes it is called as :
int bioskey(int cmd);(in Borland c++),It just uses the int 16h to function.Your isr is too complex and difficult to read and work correctly.You can just use bioskey(0) to read the correct key.If the lower byte of the return code is 0,then the key is a function key;else it's a character key.if cmd is set to 0,it will read the buffer and if no key is in buffer it will wait until some key presses;if cmd is set to 1 it will return whether any  key is pressed;if is set to 2,it will return the status key of the keyboard.
  In your  C file,you can write like this:
  #include<bios.h>  
  ....
  int key=bioskey(0);
  if(key&0xff)
     //the key is a character key
   else
    //the key is a function key
   ...
  If no this head file,you can just write the function like below:
  int bioskey(int cmd)
  {
   asm{
    mov ax,cmd
    int 0x16
    }
   return _AX;
  }
  Wish can help you!

 
0
 

Author Comment

by:beyonddeath
Comment Utility
I know what asembly is i just dont know how to program in it...
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Same difference.  If you can't program in assembly, you really shouldn't be considering hooking interrupts, that is an assembly intensive operation.

What about my questions?  I can't help you unless I know what it is you want to do?
0
 

Author Comment

by:beyonddeath
Comment Utility
i want to be able to make an interface that you push tab to get from a menu back down to another menu and also a startup script (done already) that goes until you push esc.  I want in the menu to be able to move using the arrows but i also need access to scanf as well.  Thanks allot

i want to learn asembly but from what ive seen its hard as hell.  ive been working in c and c++ for 3 years but this is my first really good program.

Thanks
0
 

Author Comment

by:beyonddeath
Comment Utility
sorry i was in a rush to get to school i missed answering before I am currently hung up with another prob I am calculating a percentage using a float and its going through an extensive if else thing to figure out how much of the percentage bar to print but its not actually calculating it its staying at 0 until it gets to 100 percent when it goes to a 100 percent whats the deal

this is the equation:
float = int1 / int2 * 100;
this isnt working int 1 is the amount of the int 2 its not allowed to go over int 2 then its put in an integer form and gone through to find how high it is, but i print it off to debug it its always equal to 0.000000 is this unusual?
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
but my point is why are you hooking the keyboard interrupt vector?  Is there a reason you need to do this?  From what you've stated you need to accomplish, I can see absolutely no reason to this.  You simply need to read  input using an unbuffered input technique, like I've suggested.

convert the int's to floating point before the division, otherwise you will get an int result which doesn't contain decimals.  Like

float = (float) int1 / (float) int2 * 100;

or you can do the multipley first like

float = (100*int)/int2

but that again will do integer division, but the numertor is larger, so you probably won't get zero.  (The right choice depends on what you need to get done, but mostlikely the first choice is the one you need.)
0
 

Author Comment

by:beyonddeath
Comment Utility
I got this source from a friend but thats an example of what i sort of need to do, i dont understand it in the least bit, he didnt make it either.

Thats the kind of thing i want. i need it so its not line buffered like you said, but i want all the buttons on a standard keyboard.

Thanks for all the help
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Then forget interrupts.

Do you have getch() or _getch()?  Those will be the easiest way to do it.  otherwise, you will have to use the functions I wrote bove.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:beyonddeath
Comment Utility
got getch() but it doesnt seem to return what i want it to return i need it to return if it is enter ENTER if its esc ESC etc etc etc will your do that?
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Mine will but it will be more work,  Lets see if getch() does work.  First of all, it should return a character as soon as it is typed, does it?  (i.e. no need to wait for a return)  

If so then see what it returns when you press an extended key.  it should return two characters (you have to call it twice)  the first character will be either 0x00 or 0x0E. then the 2nd character wll be from the table above.  does it?

if it works like that, then you can write a procedure that returns "characters" using 16 bit (or larger) integers.  The procedure would use getch()  (or if needed, the functions I wrote) to get a character, if the character is not 0x00 or 0x0E then it converts the character to the integer type and returns.  If the character is 0x00 or 0x0E, then the procedure gets the next character.  It then returns a value that uses this 2nd value in the low byte and some value in the high byte that identifies this as an extended key.  Like you might set the high bit.  

The code that uses this procedure can then differentiate between regular keys and extended keys by looking at the high byte and can determine which character/extended key it has using the low byte.

continues
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
typedef unsigned short ExtChr;

ExtChr GetChar()
{
   ExtChr Chr = 0;
   Chr = getch();
   if (Chr == 0x00 || Chr == 0x0E)
   {
      Chr = getch(); // Get the next character.
      Chr |= 0x8000; // Indicate this is an extended key.
   }
   return ExtChr;
}

// Test if an extended char is for an extended key (function key)
bool IsExtendedKey(ExtChr)
{
    return (ExtChr & 0x8000) != 0;
}

// Test if an extended char is for an ASCII key (regular key)
bool IsASCIIKey(ExtChr)
{
    return (ExtChr & 0x8000) == 0;
}

// Get ASCII value of a regular key
char GetASCIIValue(ExtChr)
{
    return ExtChr & 0x00FF;
}

// Get value of extended key
char GetExtendedValue(ExtChr)
{
    return ExtChr & 0x00FF;
}

continues
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
to use this to get input from the user you might do somethign like

const char Backspace = 0x0E;
const char Enter = -0x1C;

const int MaxLen = 10;
char Data[MaxLen];
int Pos = 0;
bool Done = false;

while (!Done)
{
    // code to display the current input in Data[] here.
    ExtChr Chr = GetChr();
    if (IsASCIIKey(Chr)) // if a regular key
    {
       if (Pos < MaxLen) // If there is room.
            Data[Pos++] = GetASCIIValue(Chr); // store char typed.
    }
    else // If this is a funcion key.
    {
         switch (GetExtendedValue(Chr))
         {
              case BackSpace: // If a backspace was typed.
                   if (Pos > 0)  // if there is input.
                      --Pos; // remove the input.
                   break;
              case Enter; // If the enter key was typed.
                   done = true;
         }
    }
};


All of this stuff will work with getch() if getch() works ass needed or with the functions I suggested, if necessary.
0
 

Author Comment

by:beyonddeath
Comment Utility
Well so close... it seems to have parse errors on all the lines to do with returns i dont know why but I have a strange feeling like commenting them could have undesirable effects ;)

i see where you are going with this but is there a way to do it so i can compile it... ie using a global variable that doesnt need to be returned every time.

Thanks allot
0
 

Author Comment

by:beyonddeath
Comment Utility
ok heres somthing interesting i get getch to respond to me and now my while loop is a do while loop like this:
i used n as a test that i know should work.
#define n 49
do
{
stuff im not typing here that has no effect ;)
}
while(getch != n);
return;

but know i have to push n once to start it and then it never stops? whaz up with that its seeming to me everything i write is oppisite of what i get... you probably think i suck at programming after all this ;p
owell
0
 

Author Comment

by:beyonddeath
Comment Utility
or i can get it to start but i need to push a button other than n to keep it going... i did this by
while(!(getch() != n));
0
 

Author Comment

by:beyonddeath
Comment Utility
nm i cant even push a different button to keep it going
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
I don't know what

// #define n 49
//  do
// {
//   stuff im not typing here that has no effect ;)
// }
// while(getch != n);
// return;

is supposed to do.  But whatever it is, it probalby is not a good way to do it.  

never use #define to define constants, use "const int" instead like I did in my code.  There are dozens of reasons.  There is no reason to use #define in that way in C++.

getch without parenthesis (getchr()) doe not call the function.  it is a pointer to the functtion.

What are you comparing the return value of getch() (which you mean to be doing, but aren't) with a number (49)?  49 is the ASCII value of '1'.  Wouldn't it be easier to compare with '1'?
0
 

Author Comment

by:beyonddeath
Comment Utility
it is supposed to keep looping until the user pushes n but you need to push n to start the loop then every time before it reiterates itself.

and i forgot to type the () on getch its in the actual program.

Thanks for all the help were getting close
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
getch() waits until a key can be returned.  Look for a function called keypressed() or something like that.  (Again it is non-standard)  then you would do

while (!KeyPressed() && getch() !=  'n')
{  
    // do something.
}
0
 

Author Comment

by:beyonddeath
Comment Utility
ok, so what about using getch for arrows like this would i just need to define or as you got mad at me for const int  for the arrows?  using the numbers i have in that big list...

Thanks I hope this works i am going to try your KeyPressed().
0
 

Author Comment

by:beyonddeath
Comment Utility
i just searched all the include files i dont have KeyPressed() can you post it?

Thanks
0
 
LVL 22

Accepted Solution

by:
nietod earned 375 total points
Comment Utility
Its not something that can be posted.  It part of the run-time library.   Its non-standard so there is no guarantee that you have it.  apparently you don't.  

You will have to use the inline assembly code I posted above to test if there is a key waiting, like

bool IsKeyWaitng()
{
   int CharacterReady = 1;
    _asm MOV AH 01H
   _asm INT 16H
   _asm JNZ AROUND
   _asm MOV CharacterReady,0
   _asm AROUND:
   return CharacterReady != 0;
}
0
 

Author Comment

by:beyonddeath
Comment Utility
thing is i cant compile that i jsut got a new compiler and the source i had before should compile if it does i will give you the points for all the help i understand this all alot better now

Thanks
0
 

Author Comment

by:beyonddeath
Comment Utility
Ok it works i will accept a comment as answer now THANKS ALLOT for all the help
0
 

Author Comment

by:beyonddeath
Comment Utility
Seeing as the question never got exactly answered half the points are your ;)
0
 

Author Comment

by:beyonddeath
Comment Utility
nm heheh
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now