Page 1 of 1

test if ctrl or alt or shift is pressed

Posted: Fri 27 May 2005, 03:50
by GuestToo
i wrote a C program that tests if the ctrl or alt or shift keys are pressed

i thought it might be useful when Puppy was booting ... for example, hold the ctrl key and it will not use a pup001 file ... something like that

it has to run with root priviledges for it to work properly

Useage:

port60
if [ $? -eq 29 ];then
# do something
fi

Brilliant

Posted: Fri 27 May 2005, 04:28
by Lobster
This should solve all the 'simple' versus 'boot up options'. With Puppy you can have your cake and all the trimmings.

Press Ctrl for extended boot options in small letters bottom right of the splash screen - see splash screens are useful.

Good job G2

Posted: Fri 27 May 2005, 05:18
by GuestToo
i don't know how well it will work
it wouldn't allow you to pass boot options to the kernel, like noacpi
if it works well enough, it might be useful though

C doesn't seem to have a simple way to check if certain keys are pressed

i tried writing a few nasm programs ... the kernel doesn't let you access the ports directly ... maybe it would if you called ioperm, but if you do that, you might as well write the whole program in C

maybe there's an easier way, i am not a C expert

Posted: Fri 27 May 2005, 12:42
by BarryK
GuestToo,
Thanks for that, I think it may have its uses...

for example, as we haven't solved the first-boot problem with multisession, holding down one of those keys could be the way to tell Puppy to bootup as multisession.

Posted: Fri 27 May 2005, 20:10
by GuestToo
this is just the first thing i got to work

this program reads port 60 directly ... which is the ps2 port ... so this probably won't work for usb keyboards

i think a more straight-forward approach would be better ... C doesn't seem to have a simple way of checking keys ... there is getchar, but that stops and waits until you press a key and press enter

i tried a few things calling the kernel routines directly using nasm, but didn't get that working yet

there are ways to do this properly ...

fgetc

Posted: Sat 28 May 2005, 06:09
by Jesse
Yeah, I did wonder about how compatible a program would be with different keyboard interfaces,
though I did have a thought, instead of reading from hardware, would it be possible to just do a fgetc(stdin) ?
I don't know if this would work at boot time, but I think that the kernel has to detect and configure at least one keyboard plugged into system at some point., run your program after that point and use fgetc. Maybe this would work, maybe it wont, gotta try to see :-) I'm upto my eyeballs in cdrom ioctrls at the moment.

Jesse