Keylock

This is a discussion on Keylock within the C Programming forums, part of the General Programming Boards category; Hi there 1)Is there any method to lock specific keys on the keyboard while getting input 2) How is the ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    45

    Keylock

    Hi there

    1)Is there any method to lock specific keys on the keyboard while getting input

    2) How is the memory allocation done in union when it contains one integer variable, one float variable and three character variables


    thanx

    raajesh

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Keylock

    Originally posted by rajesh23
    Hi there

    1)Is there any method to lock specific keys on the keyboard while getting input

    2) How is the memory allocation done in union when it contains one integer variable, one float variable and three character variables
    1) Explain further. Lock how? No. No portable way. Possible a OS / compiler specific, but you'd need to expalin further what you're trying to do.

    2 ) Sounds like homework. Read up on unions, it's usually the first thing explained on how they work in any book. The size of the union is the size of the largest element.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    45
    Hello

    How the memory is shared by the variables in it. bcoz there are three char occupying 3 bytes and one integer occupying two bytes have to share the four bytes of float variable. Hope you get it right

    can u explain now, also is the allocation machine/OS dependent?

    Regarding locking selected keys in the keyboard, we want to do that for validating the input when obtained through scanf. Say u want to lock all the keys except 0 to 9 when u want to enter an integer


    thanx

    RAAJESH

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    18
    It is i would say OS specific.But if you intend doing it in DOS then you could use interrupts and scan codes for the keys to do this.

    Have a look here. http://vwop.port5.com/advanced/directkey.html

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    How the memory is shared by the variables in it. bcoz there are three char occupying 3 bytes and one integer occupying two bytes have to share the four bytes of float variable. Hope you get it right
    Of course it's shared. That's what a union is. The question you originall posted was how it was allocated. I answered that: It uses the size of the largest element.

    You next problem is that you assume that an integer is 2 bytes. This is only true on old, outdated compilers. Get a new compiler. No one uses 16 bit compilers any more.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    Hi,
    >>Is there any method to lock specific keys on the keyboard while getting input
    Why cant use Isdigit()?.Use can also go for Scancode also.
    Saravanan.T.S.
    Beginner.

  7. #7
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    I've never hurd of unions before do you malloc memory as *void and just asign differnt types of values into it? And could someone please post a link desribing how to do this in linux since it was OS dependent.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  8. #8
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Unions

    Unions are class types that can contain only one data element at a time (although the data element can be an array or a class type). The members of a union represent the kinds of data the union can contain. An object of union type requires enough storage to hold the largest member in its member-list. Consider the following example:
    Code:
    #include <stdlib.h>
    #include <string.h>
    #include <limits.h>
    
    union NumericType        // Declare a union that can hold the following:
    {
        int         iValue;  // int value
        long        lValue;  // long value
        double      dValue;  // double value
    };
    
    int main( int argc, char *argv[] )
    {
        NumericType *Values = new NumericType[argc - 1];
    
        for( int i = 1; i < argc; ++i )
            if( strchr( argv[i], '.' ) != 0 )
               // Floating type. Use dValue member for assignment.
                Values[i].dValue = atof( argv[i] );
            else
               // Not a floating type.
            {
                    // If data is bigger than largest int, store it in
                    //  lValue member.
                if( atol( argv[i] ) >  INT_MAX )
                    Values[i].lValue = atol( argv[i] );
                else
                    // Otherwise, store it in iValue member.
                    Values[i].iValue = atoi( argv[i] );
            }
          return 0;
    }
    This was copied from the MSDN Library.

    as for locking keys... it depends on the key, if its a special key then you have to use special ways of doing it, if its an alphanumeric key than use :
    Code:
    getch(); //from conio.h
    and if its a key that you want locked discard it if its not, do what ever you want with it (just remember to echo it back).

    and for a linux version of getch, see the Linux Programming FAQ on the Linux programming board.

    -LC
    Last edited by Lynux-Penguin; 08-27-2003 at 03:01 PM.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  9. #9
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    So a union is likea struct?
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >So a union is likea struct?
    A union is basically a structure that takes up only enough memory for the largest member. Because of that, only one member at a time can exist in the memory allowed.
    My best code is written with the delete key.

  11. #11
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    ah, okey, I see
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21