Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Asm для Windows/Dos > состояние клавиш...


Автор: alexmikt 30.10.2009, 23:35
Помогите пожалуйста с решением задачки.....

Написать программу, определяющую состояние клавиш Ins, CapsLock, NumLock, ScrollLock и выполняющую следущие действия: вывод на экран соответствующего сообщения, если не одна из них не нажата; вывод на экран названий нажатых клавиш.

заранее благодарен!

Автор: Goodwin98 31.10.2009, 00:09
Смотри в сторону функции 2 int 16h.
Или проверяй байт по аддресу 0000h:0417h

Автор: piritus 31.10.2009, 00:41
Код

.186
.model    small
.stack    100h

.data 
    msgON     db "ON",13,10,"$"
    msgOFF   db "OFF",13,10,"$"
    msgCL     db "CapsLock   - ","$"
    msgNL    db "NumLock    - ","$"
    msgSL     db "ScrollLock - ","$"
    
.code
IsCapsLockOn proc
    xor        ax,ax    ; Zero out the content of the AX register  
    mov    ah,02h  ; Keyboard shift status function  
    dw    16CDh   ; Issue the interrupt  
    shr        al,06h  ; Move the 7th bit to the rightmost position  
    and    al,01h  ; Mask all other bits out  
    ret             ; Return to the calling procedure
IsCapsLockOn endp
IsNumLockOn proc
    xor        ax,ax   ; Zero out the content of the AX register  
    mov        ah,02h  ; Keyboard shift status function  
    dw      16CDh   ; Issue the interrupt  
    shr        al,05h  ; Move the 6th bit to the rightmost position  
    and     al,01h  ; Mask all other bits out  
    ret             ; Return to the calling procedure
IsNumLockOn endp
IsScrollLockOn proc
    xor        ax,ax   ; Zero out the content of the AX register  
    mov    ah,02h  ; Keyboard shift status function  
    dw      16CDh   ; Issue the interrupt  
    shr    al,04h  ; Move the 5th bit to the rightmost position  
    and    al,01h  ; Mask all other bits out  
    ret             ; Return to the calling procedure
IsScrollLockOn endp

start:
    mov        ax,@data        
    mov        ds,ax        
    
;---------- Test CapsLock ----------
    mov        dx,offset msgCL 
    mov        ah,9              
    int        21h    
    call    IsCapsLockOn
    test    al,al
    jne CLON_p

    mov        dx,offset msgOFF    
    jmp        PrintCL
    
CLON_p:
    mov        dx,offset msgON  

PrintCL:
    mov        ah,9              
    int        21h                 
;-----------------------------------

;---------- Test NumLock -----------
    mov        dx,offset msgNL 
    mov        ah,9              
    int        21h    
    call    IsNumLockOn
    test    al,al
    jne NLON_p

    mov        dx,offset msgOFF    
    jmp        PrintNL
    
NLON_p:
    mov        dx,offset msgON  

PrintNL:
    mov        ah,9              
    int        21h                 
;-----------------------------------

;--------- Test ScrollLock ---------
    mov        dx,offset msgSL 
    mov        ah,9              
    int        21h    
    call    IsScrollLockOn
    test    al,al
    jne SLON_p

    mov        dx,offset msgOFF    
    jmp        PrintSL
    
SLON_p:
    mov        dx,offset msgON  

PrintSL:
    mov        ah,9              
    int        21h                 
;-----------------------------------

    mov        ax,0C07h    
    int        21h            
    
    mov        ax, 4C00h    
    int        21h        
end start


Автор: alexmikt 1.11.2009, 09:51
Спасибо огромное!!!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)