Thread: Locking all keybord keys exept numbers 0-9

  1. #1
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90

    Locking all keybord keys exept numbers 0-9

    As the thread name says.
    How would I lock all keys without the numbers 0-9?

    Thanks

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    howabout, instead of locking everything. just create functionality for 1-9? and nothing else?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Lock? You mean, not recieve them?

    Using getch(), you could do something like this:
    Code:
    int c;
    
    for(;;) {
        c = getch();
        if(isdigit(c)) {
            std::cout << c;
            // process number here
        }
    }
    but getch() isn't standard.

    You could just use getline() and ignore anything that isn't isdigit().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Try to imagine someone asking which OS/Compiler.

    Nevermind - Which OS/Compiler?

    What constitutes "locked" anyway when you have certain keys like alt-tab in windows for choosing other programs - do you want to lock those as well?

  5. #5
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    What constitutes "locked" anyway when you have certain keys like alt-tab in windows for choosing other programs - do you want to lock those as well?
    Hmm... Yes really. Its a password as you probably understood. I dont want people to be able to just "go out" of it.

    Nevermind - Which OS/Compiler?
    Windows XP
    Dev-C++

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > I dont want people to be able to just "go out" of it.
    Be careful here - if you go round just locking people out of their machines your software will be regarded as malware. Besides, if they alt-tab, it's just sending focus to another program and yours goes to the background - why would that matter to you.

    Nobody elses password input locks the whole machine in the way you seem to be wanting to.

    Seems to me all you're really after is all input, and then you apply isdigit() to each input character.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. Replies: 4
    Last Post: 03-03-2003, 03:52 PM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM