flat assembler
Message board for the users of flat assembler.
Index
> Linux > Get pushed key |
Author |
|
binary108 20 Apr 2004, 07:26
Mda...
it seems something wrong in my post... How can seample console program get scan-code (or another identifer) of seangle pushed button (or key - i don't know what's right) on keyboard? Sorry for my bad english... |
|||
20 Apr 2004, 07:26 |
|
coconut 20 Apr 2004, 21:03
Last edited by coconut on 10 Mar 2005, 21:18; edited 1 time in total |
|||
20 Apr 2004, 21:03 |
|
gorshing 20 Apr 2004, 21:23
I was unaware that you could use a hook for a system event in linux. Does anybody have any examples?
As for hiding characters being typed. I would look into using the ncurses library. Otherwise, I would think that it would be different for each type of terminal ... I don't know though _________________ gorshing |
|||
20 Apr 2004, 21:23 |
|
0xkorkut 10 Mar 2005, 20:42
Here is an example of getting single keys using linux kernel calls
i tried my best Code: ;this proggy mainly shows the next char in 1 second after you typed ;i hate to see characters "being typed" while im not touching the keyboard ;so i added a buffer flush code ;i hope it would help someone ;equates are stolen from asmutils include files (os_linux.inc) ;some of them also can be found at www.lxhp.in-berlin.de/lhpioctl.html ;but they are well hidden so try searching the document for "termios" ;i came across this info after examining "snake" proggie in asmutils. ;here the keyword is "non-canonical". after googling for "canonical tty" ;i found this addr http://ou800doc.caldera.com/en/SDK_sysprog/_TTY_in_Canonical_Mode.html ;check out the link topright says "terminal device control" you should see ;a lot of good docs here ;also check out http://ou800doc.caldera.com/en/man/html.7/termio.7.html ;for better explanations for termios ;hold down the key to see what happens. ESC to quit. ;i apologize for my poor programming skills but i mainly tried to ;write more understandable code for newbies like me format ELF executable entry start TCGETS equ 0x5401 TCSETS equ 0x5402 TCFLSH equ 0x540b TCIOFLUSH equ 2 ;flush both input output TCOFLUSH equ 1 ;flush output TCIFLUSH equ 0 ;flush input ICANON equ 2 ECHO equ 8 STDIN equ 0 STDOUT equ 1 SYS_NANOSLEEP equ 162 SYS_IOCTL equ 54 SYS_READ equ 3 SYS_WRITE equ 4 SYS_EXIT equ 1 section readable writeable start: call begingetkey ;enter non-canonical mode ;close local echo mainloop: mov ebx,timer ;wait a little to fill keyboard buffer mov ecx,timer2 ;simulate a time consuming process mov eax,SYS_NANOSLEEP int 0x80 mov ebx,STDIN mov ecx,key mov edx,1 mov eax,SYS_READ int 0x80 push eax ;number of read bytes mov ebx,STDIN ;flush extra chars written to the mov ecx,TCFLSH ;buffer while we hold down the key mov edx,TCIOFLUSH ;in fact i dont know how it really effects mov eax,SYS_IOCTL ;but i prefer to flush both buffers int 0x80 ;it seems ok for this code pop eax test eax,eax ;read anything? jz mainloop cmp byte [key],0x1b ;ESC key quit jz quitloop inc byte [key] ;just to see WE are echoing ;show next char mov ebx,STDOUT mov ecx,key mov edx,1 mov eax,SYS_WRITE int 0x80 jmp mainloop quitloop: call endgetkey ;restore previous state and quit mov eax,ebx mov eax,SYS_EXIT int 0x80 begingetkey: mov ebx,STDIN ;get old state here mov ecx,TCGETS mov edx,old_termios mov eax,SYS_IOCTL int 0x80 mov ecx,19 ;and make a copy mov esi,old_termios mov edi,new_termios rep movsb and [new_termios.c_lflag],dword not(ICANON or ECHO) ;turn off echo mov byte [new_termios.VMIN],0 ;turn off canonical mode mov byte [new_termios.VTIME],0 ;we dont want to wait for keystrokes mov ebx,STDIN mov ecx,TCSETS mov edx,new_termios mov eax,SYS_IOCTL int 0x80 ret endgetkey: ;clean up mov ebx,STDIN mov ecx,TCSETS mov edx,old_termios mov eax,SYS_IOCTL int 0x80 ret timer: ;timespec structure dd 1 ;seconds dd 0 ;nanoseconds timer2: dd 1 dd 0 old_termios: ;termios structure NOT termio .c_iflag: rd 1 .c_oflag: rd 1 .c_cflag: rd 1 .c_lflag: rd 1 ;.c_cc rb 4 .VMIN: rb 1 .VTIME: rb 1 rb 13 new_termios: .c_iflag: rd 1 .c_oflag: rd 1 .c_cflag: rd 1 .c_lflag: rd 1 ;.c_cc .VINTR: rb 1 .VQUIT: rb 1 .VERASE: rb 1 .VKILL: rb 1 .VEOF: rb 1 .VMIN: ;in canonical mode VEOL rb 1 .VTIME: ;in canonical mode VEOL2 rb 1 .VSWTCH: rb 1 .VSTRT: rb 1 .VSTOP: rb 1 .VSUSP: rb 1 .VDSUSP: rb 1 .VREPRINT: rb 1 .VDISCARD: rb 1 .VWERASE: rb 1 .VLNEXT: rb 1 rb 3 ;reserved key: rb 1 _________________ .cC}< Eat your veggies >{Cc. |
|||
10 Mar 2005, 20:42 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.