-2

I want to see how can I change a key on keyboard to act like another key. for example by clicking Alt I want the system think it is Ctrl using c++, is it possible?

Carey Gregory
  • 6,836
  • 2
  • 26
  • 47
  • (assuming you are on Windows, C++ alone will not let you do that. you need to add a Windows hook. have a look at this : http://stackoverflow.com/questions/17419562 – Max Sep 25 '13 at 19:28
  • On what OS? Admin allowed or not? – RedX Sep 25 '13 at 19:28
  • It is on windows and yes the admin is allowed I am the admin – amirali shahinpour Sep 25 '13 at 19:33
  • @Max - using the Windows Hook API calls can be done with only C++. – egrunin Sep 25 '13 at 19:33
  • This is not really a C++ question, C++ as a language does not even have the concepts of ctrl and alt keys as far as I know. This is operating system question. Please re-tag and add more details to question text. – hyde Sep 25 '13 at 19:34
  • It **is** a C++ question, just not **only** a C++ question. (I've edited his tags.) – egrunin Sep 25 '13 at 19:37
  • Perhaps the OP wants to write a program that'd allow him to arbitrarily remap keys AND wants to write as much as possible of it in C++? – Chiffa Sep 25 '13 at 19:38
  • @Chiffa Yes completly correct, I want to make a key works exactly as Ctrl does and I want to do it with c++ because I know it the best – amirali shahinpour Sep 25 '13 at 19:46
  • All right, now your intent is clear for all. But, as stated, you can't do it in C++ only. – Chiffa Sep 25 '13 at 19:49
  • This isn't even a programming question. It's a system configuration question. You can create a custom keyboard layout or swap the keys at the driver level. Many options given [here](http://superuser.com/questions/36920/how-can-i-remap-a-keyboard-key). – Raymond Chen Sep 25 '13 at 20:00

2 Answers2

2

If you are on windows then you may interested to know LowLevelKeyboardProc callback function and HOOKS

HOOKS

A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure.

LowLevelKeyboardProc callback function

An application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function every time a new keyboard input event is about to be posted into a thread input queue. The HOOKPROC type defines a pointer to this callback function. LowLevelKeyboardProc is a placeholder for the application-defined or library-defined function name.

Also check Using Hooks

Community
  • 1
  • 1
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

It's not an identical, situation, but this Stack Overflow question about C++ Win32 keyboard events may give you the start you need.

Community
  • 1
  • 1
egrunin
  • 24,650
  • 8
  • 50
  • 93