Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scan Codes 3

Status
Not open for further replies.

spec85

Programmer
May 7, 2004
4
AU
Hi

I'm new to assembly so do forgive me if I have overlooked something.

I am writing a program that waits for the ctrl + alt + a keys to be pressed at the same time.
I’m using int 16h function 00h to get the key and cmp that it is a ‘a’

I then want to use int 16h function 2h to see if the ctrl + alt keys where pressed.

These two functions work fine separately but when put together they don’t work.
The problem is when you are holding ctrl + alt, ‘a’ doesn’t = ‘a’ anymore.

How can I get around this? Should I be using the a scan code?
If so what is the scan code for ctrl + alt + a?

Thanks for any help you can offer

Spec

 
The Below program is ment to: loops waiting for a letter. Then checks the scan code equals "1E01" which should be ctrl+A.

Sadly it doesn't work. What am I doing wrong?

START:
mov ax, @DATA
mov ds, ax

letterLoop:
mov ah, 00H
int 16h ;get a key, return in AX

mov al, ah ;copy scan code into al
cbw ;move ah into ax
cmp ax, 1E01H
jne letterLoop

mov ax,4c00h
int 21h ;end program


END START
 
have a look at what cbw does. All it does is extend the sign-bit (highest bit) of a byte to fill the whole word, thus preserving negative-value bytes as negative-value words. After cbw, the top half of ax (which is exactly the same thing as saying ah) will always be 0 or 0FFh. It can't ever be 01Eh
 
OK
what if I
int 16,00
cmp al,'a'
if yes
then
int 16,02
cmp al, 00001100B

Shouldn't that work?



 
Why don't you try using the 'Get Keyb. Flags' BIOS function (ah=02h, int 16h). The return byte in AL gives keyboard flags...

AL: bit description
00h r. shift
01h l. shift
02h CTRL
03h ALT
04h SCROLL LK
05h NUM LK
06h CAPS LK
07h INSERT

As an example of what I mean, look at the following code:
Code:
key_loop:
  mov ah,02h
  int 16h
  and al,0ch
  cmp al,0ch
  jne key_loop
  mov ah,00h
  int 16h
  cmp al,'a'
  je key_press
  cmp al,'A'
  je key_press
  jmp key_loop

key_press:
The code is slightly flawed in that the keyboard buffer is not emptied before cmp to 'a' or 'A'. I'll leave you to do some of the work...
:)

Don't hate the player - hate the game
 
Thanks for all your help. I finally got it working.
I actually read port 60h testing for the scan code of 'a'
then I did int 16, 02 to test for ctrl+alt

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top