change keyboard keys

This is a discussion on change keyboard keys within the C Programming forums, part of the General Programming Boards category; please guys help me is it possible when i press 'a' on keyboard it should print 'n' on screen? I ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Location
    Hyderabad, Andhra Pradesh, India
    Posts
    12

    change keyboard keys

    please guys help me
    is it possible when i press 'a' on keyboard it should print 'n' on screen? I want c or c++ program



  2. #2
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Yaswanth, No one on the board will write this program for you but it is possible to write a program that does what you're looking for. Choose the language you're comfortable with and take it from there. Post any attempts you have and we'll be glad to help you out.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    Why do you want to do this? Have you considered tools like AutoIt that might be able to do this?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2012
    Location
    Hyderabad, Andhra Pradesh, India
    Posts
    12

    change keyboard keys

    Quote Originally Posted by laserlight View Post
    Why do you want to do this? Have you considered tools like AutoIt that might be able to do this?

    Just for knowledge

  5. #5
    Registered User
    Join Date
    Dec 2012
    Location
    Hyderabad, Andhra Pradesh, India
    Posts
    12
    Quote Originally Posted by caroundw5h View Post
    Yaswanth, No one on the board will write this program for you but it is possible to write a program that does what you're looking for. Choose the language you're comfortable with and take it from there. Post any attempts you have and we'll be glad to help you out.
    Thanks for responce

    I am good at C and C++ but has absolute zero knowledge in this keyboard area can yo help me

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    2,706
    If your OS/compiler support the non-standard "conio" header file, then you can adapt an example from a FAQ on this site to achieve your goal.

    FAQ > How can I get input without having the user hit [Enter]? - Cprogramming.com

    Otherwise, you'd be better off looking into other libraries, or even other languages (as already mentioned in this thread).

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    2,590
    ncurses is another option

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    There are many different ways you can do it. The smiples would to check the post#6 and read through the FAQ. When you enter key on a keyboard the corresponding ASCII valuecan be captured and check for if the the key just entered was 'a'. If it is then print 'n'.

    Code:
    int CharEntered = KeyPress();
    
    if( CharEntered == 65 || CharEntered == 97 )
    { print("n") ); }
    
    can also be written
    
    if( CharEntered == 'a' || CharEntered == 'A' )
    {   print( "n" );  }
    But as said this is a very simple approch. But however it depends on what platform and OS your working on. You can use some rich of libraries such as ncurser.h on unix platfomr.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  9. #9
    Registered User
    Join Date
    Dec 2012
    Location
    Hyderabad, Andhra Pradesh, India
    Posts
    12
    Quote Originally Posted by ssharish2005 View Post
    There are many different ways you can do it. The smiples would to check the post#6 and read through the FAQ. When you enter key on a keyboard the corresponding ASCII valuecan be captured and check for if the the key just entered was 'a'. If it is then print 'n'.

    Code:
    int CharEntered = KeyPress();
    
    if( CharEntered == 65 || CharEntered == 97 )
    { print("n") ); }
    
    can also be written
    
    if( CharEntered == 'a' || CharEntered == 'A' )
    {   print( "n" );  }
    But as said this is a very simple approch. But however it depends on what platform and OS your working on. You can use some rich of libraries such as ncurser.h on unix platfomr.

    ssharish

    Thank you very much. your code is simple and great

    I want to modify my question. If I press 'a' then 'n' button should be pressed.
    Can I achieve this by using
    Code:
    CharEntered = KeyPress();
    if( CharEntered == 65 || CharEntered == 97 )
    {
    keybd_event VK_N, 0, 0, 0  ' press N
    keybd_event VK_N, 0, KEYEVENTF_KEYUP, 0  ' release N 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. change keyboard keys
    By Yaswanth in forum C++ Programming
    Replies: 1
    Last Post: 12-23-2012, 11:07 AM
  2. Need Help on Remapping Keyboard Keys (C++)
    By GraceLC in forum C++ Programming
    Replies: 1
    Last Post: 03-15-2011, 03:49 AM
  3. C program to press keyboard keys
    By meadhikari in forum Windows Programming
    Replies: 9
    Last Post: 03-26-2010, 01:36 AM
  4. Simulate Keys with a Keyboard Hook
    By guitarist809 in forum Windows Programming
    Replies: 3
    Last Post: 11-14-2008, 08:14 PM
  5. Arrow keys as keyboard Input
    By bradleym83 in forum C++ Programming
    Replies: 3
    Last Post: 12-01-2005, 09:39 PM

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