Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Read keyboard scan codes, or how to capture ALT+Something

Posted on 2005-05-12
14
Medium Priority
?
1,247 Views
Last Modified: 2008-02-20
Hi,
I need to write a consol program that will prompt the user to enter some text strings. The strings can be both in English or German. I need to be able to capture Function keys pressed, or better yet key combinations such as Alt+A and map them to umlaut a, o, and u.
My initial idea was to embed some asm code and use it for that purpose. However, whenever I try to execute even the simplest program with embedded asm that contains any interrupt vector, I get "First-chance exception in ChapterFour.exe: 0xC0000005: Access Violation". I'm using MSVS 6.

Thanks,
Blago
0
Comment
Question by:blago
  • 4
  • 3
  • 3
  • +4
14 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 13993414
Check out the source code in the following link:
http://www.autohotkey.com/download/

Also see main link:
http://www.autohotkey.com
0
 
LVL 4

Expert Comment

by:furqanchandio
ID: 13994456
hi

the reason you are getting the intereuupt vactor error i think is because you are trying to call dos functions from VC6. VC doenot allow dos interupts to be called from it. if you use assembly you should use 32 bit assembly

cheers
0
 
LVL 16

Assisted Solution

by:PaulCaswell
PaulCaswell earned 750 total points
ID: 13994626
You can use int86 or int86x instead of asm.

Alternatively, try:

// Get a key from the keyboard.
int GetKey ( void )
{
      unsigned int key = 0;
      // No! Get it from the keyboard.
      if ( _bios_keybrd( _NKEYBRD_READY ) != 0 )
      {
            key = _bios_keybrd( _NKEYBRD_READ );
            // e0 -> Cursor key etc.
            // 00 -> Function keys.
            if ( (key & 0xff) == 0xe0 || (key & 0xff) == 0x00 )
            {
                  key = (key >> 8) | 0x8000;
            }
            else
            {
                  key = key & 0xff;
            }

      }
      return key;            
}

If this doesnt work, let me know, I've got other options.

Paul
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13995238
Could you tell us why you need map Alt-A to ä ?
Maybe there is a better alternative for this trick.
0
 

Expert Comment

by:swamp-dog
ID: 13999825
Look in MSN for AllocConsole. Note the "codepage" references.
0
 
LVL 1

Author Comment

by:blago
ID: 14002531
Paul, MSVC does not come with bios.h so the above doesn't work.
Jaime, the reason I need it done this way is because this is what my project says.
Swamp-dog, I'm trying to avoid any APIs.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 300 total points
ID: 14002711
0
 

Expert Comment

by:maheshstms
ID: 14011808
use the on keypress methof and u can get if the user has pressed alt or any other keys including the normal keys from a-z
why to go for asm
0
 
LVL 1

Author Comment

by:blago
ID: 14015524
Although I didn’t get a satisfactory answer, I will award to points to Paul since I feel that his comment came the closest to what I needed; namely API-independent and portable solution. However, Jaime also had a good solution and therefore I will open another question and give him a 100pt. Just for future reference, here is what I did:
int getChar() {
      int ret;
      ret = getch();

      if (ret == 0) {
            ret = getch()+256;
            switch(ret) {
            case 315:
                  return 132;
                  break;
            case 316:
                  return 148;
                  break;
            case 317:
                  return 129;
                  break;
            case 318:
                  return 142;
                  break;
            case 319:
                  return 153;
                  break;
            case 320:
                  return 154;
                  break;
            }
      }
      else
            return ret;
}

The above code maps the first 6 function keys to umlaut letters. Sorry, no ALT key detection with Microsoft’s getch() implementation.
0
 
LVL 1

Author Comment

by:blago
ID: 14015527
Ooops, didn't know I can split points
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 14016843
Would you like me to reopen the question so you can split points?

Paul
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 14016871
Appears to be that the autor did split points
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 14016893
Oops! That was dumb of me! Thanks Jaime.

Paul
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 14016917
Will tell nobody  ;)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.
Suggested Courses

810 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