Keyboard mapping->sysctl variable

Is there a way to set a keyboard mapping to adjust a sysctl variable? My hp laptop, with the acpi_hp module loaded, I can controll the brightness but only by manually changing the sysctl variable... does anybody know a way where I can map this function to a key to allow this laptop to be usable with freebsd?
 
Does your DE/WM have a keyboard shortcut application? E.g XFCE has Settings - Keyboard - Application Shortcuts, where you can simply map a command to a keyboard shortcut (e.g. I have 'killall npviewer.bin' mapped to 'Ctl \'). Sysctl commands need root, but you could use password-less sudo for that specific command, I guess.
 
Code:
hw.acpi.video.lcd0.brightness: 100
hw.acpi.video.lcd0.levels: 100 48 19 24 29 34 39 48 55 61 71 80 100

Now I just need two scripts, one to increase to the next available level when run, and one to decrease. I don't really know how to go about that though... if anyone has the time to show me how, via sh/csh scripting, i could retrieve the value of hw.acpi.video.lcd0.levels and store that in the variable for the rest of the script? Then i think it would be as simple as if hw.acpi.video.lcd0.brightness=x then hw.acpi_video.lcd0.brightness->y.
 
Solution!

Well, run xev and xbindkeys shows that all fn keys return a value except for switch to VGA out and brightness up and brightness down. I'm not sure why because all these functions work perfectly in linux and even in opensolaris. More investigation is needed. For now, however instead of binding Fn+[F7,F8] I use WinKey+[F7,F8] and the following scripts (which i am aware could be consolidated but I know virtually no shell scripting so)... here we go...

first you must ensure the proper modules are loaded (obviously replace acpi_hp with the relevant module)
Code:
kldload acpi
kldload acpi_video
kldload acpi_hp

Now running sysctl hw.acpi.video.lcd0 shows
Code:
hw.acpi.video.lcd0.brightness: 100
hw.acpi.video.lcd0.fullpower: 100
hw.acpi.video.lcd0.economy: 48
hw.acpi.video.lcd0.levels: 100 48 19 24 29 34 39 48 55 61 71 80 100

These levels may be different for you, so just follow this form, here is the script to increase brightness, brightup.sh:
Code:
#!/bin/csh
# increase lcd0 brightness

set brightup = `sysctl -n hw.acpi.video.lcd0.brightness`

switch ($brightup)
	case 19:
		sudo sysctl hw.acpi.video.lcd0.brightness=24
		breaksw
	case 24:
		sudo sysctl hw.acpi.video.lcd0.brightness=29
		breaksw
	case 29:
		sudo sysctl hw.acpi.video.lcd0.brightness=34
		breaksw
	case 34:
		sudo sysctl hw.acpi.video.lcd0.brightness=39
		breaksw
	case 39:
		sudo sysctl hw.acpi.video.lcd0.brightness=48
		breaksw
	case 48:
		sudo sysctl hw.acpi.video.lcd0.brightness=55
		breaksw
	case 55:
		sudo sysctl hw.acpi.video.lcd0.brightness=61
		breaksw
	case 61:
		sudo sysctl hw.acpi.video.lcd0.brightness=71
		breaksw
	case 71:
		sudo sysctl hw.acpi.video.lcd0.brightness=80
		breaksw
	case 80:
		sudo sysctl hw.acpi.video.lcd0.brightness=100
		breaksw
	case 100:
		sysctl hw.acpi.video.lcd0.brightness
		breaksw
	default:
		breaksw
endsw

and to decrease, brightdown.sh:
Code:
#!/bin/csh
# decrease lcd0 brightness

set brightdown = `sysctl -n hw.acpi.video.lcd0.brightness`

switch ($brightdown)
	case 19:
		sysctl hw.acpi.video.lcd0.brightness
		breaksw
	case 24:
		sudo sysctl hw.acpi.video.lcd0.brightness=19
		breaksw
	case 29:
		sudo sysctl hw.acpi.video.lcd0.brightness=24
		breaksw
	case 34:
		sudo sysctl hw.acpi.video.lcd0.brightness=29
		breaksw
	case 39:
		sudo sysctl hw.acpi.video.lcd0.brightness=34
		breaksw
	case 48:
		sudo sysctl hw.acpi.video.lcd0.brightness=39
		breaksw
	case 55:
		sudo sysctl hw.acpi.video.lcd0.brightness=48
		breaksw
	case 61:
		sudo sysctl hw.acpi.video.lcd0.brightness=55
		breaksw
	case 71:
		sudo sysctl hw.acpi.video.lcd0.brightness=61
		breaksw
	case 80:
		sudo sysctl hw.acpi.video.lcd0.brightness=71
		breaksw
	case 100:
		sudo sysctl hw.acpi.video.lcd0.brightness=80
		breaksw
	default:
		breaksw
endsw
 
continued...

the other option, and probably a wiser one, would be to give passwordless sudo permissions not to sysctl, but to the shell scripts, which i would believe work because their daughter processes should still be given root privileges. (correct me if I'm wrong, please). I placed these scripts in /usr/bin, but place them anywhere in your path and chmod +x. Then in KDE4,
1) Click KMenu
2) Settings
3) System Settings
4) Input Actions
5) Select "Preset Actions"
6) Click "Edit" -> "New" -> "Global Shortcut" -> "Command/URL"
7) Under Trigger select your keymap
8) Under Action enter the path to your script and configure sudo.

Sorry if this was annoyingly redundant, I always like to make dummies like how-to's... certainly not doing it to insult anyones knowledge..
 
hi, I haved read the post about "keyboard mapping -> sysctl".
http://forums.freebsd.org/showpost.p...55&postcount=4
I will just ask where do you place the two script, and what is the mechanism of launch?? (I don't understand how is the script launched).

Thanks.
Ježek Jan

I have a new script which I will post below, you either run "brightness up" or "brightness down" and it will adjust accordingly. However, I am not an expert scripter so you'll have to adjust the sysctl variables according to your `sysctl -n hw.acpi.video.lcd0.brightness` values. You can either run 'brightness' in the console, in the terminal window, or as I do it, use your window manager to create a keyboard shortcut to run the commands. As such mine is set when I press "Mod+F7" it runs the command "brightness down" and lowers the brightness, and "Mod+F8" for "brightness up". For some reason on my laptop, Fn+F[7,8] don't work but the rest (Fn+F[1-6,9-Delete]) all do. anyways here's the new brightness script:

Code:
#!/bin/csh
# lcd0 brightness
# hw.acpi.video.lcd0.levels: 100 48 19 24 29 34 39 48 55 61 71 80 100

set brightness = `sysctl -n hw.acpi.video.lcd0.brightness`
if ( "X$brightness" == "X" ) then
	echo "Error retrieving hw.acpi.video.lcd0.brightness sysctl."
	echo "Please ensure the acpi_video module is loaded,"
	echo "Run kldload acpi_video."
else
switch ($1)
	case down:
		switch ($brightness)
			case 19:
				sysctl hw.acpi.video.lcd0.brightness
				breaksw
			case 24:
				sudo sysctl hw.acpi.video.lcd0.brightness=19
				breaksw
			case 29:
				sudo sysctl hw.acpi.video.lcd0.brightness=24
				breaksw
			case 34:
				sudo sysctl hw.acpi.video.lcd0.brightness=29
				breaksw
			case 39:
				sudo sysctl hw.acpi.video.lcd0.brightness=34
				breaksw
			case 48:
				sudo sysctl hw.acpi.video.lcd0.brightness=39
				breaksw
			case 55:
				sudo sysctl hw.acpi.video.lcd0.brightness=48
				breaksw
			case 61:
				sudo sysctl hw.acpi.video.lcd0.brightness=55
				breaksw
			case 71:
				sudo sysctl hw.acpi.video.lcd0.brightness=61
				breaksw
			case 80:
				sudo sysctl hw.acpi.video.lcd0.brightness=71
				breaksw
			case 100:
				sudo sysctl hw.acpi.video.lcd0.brightness=80
				breaksw
			default:
				breaksw
		endsw
	breaksw
	case up:
		# increase lcd0 brightness
		# hw.acpi.video.lcd0.levels: 100 48 19 24 29 34 39 48 55 61 71 80 100
		switch ($brightness)
			case 19:
				sudo sysctl hw.acpi.video.lcd0.brightness=24
				breaksw
			case 24:
				sudo sysctl hw.acpi.video.lcd0.brightness=29
				breaksw
			case 29:
				sudo sysctl hw.acpi.video.lcd0.brightness=34
				breaksw
			case 34:
				sudo sysctl hw.acpi.video.lcd0.brightness=39
				breaksw
			case 39:
				sudo sysctl hw.acpi.video.lcd0.brightness=48
				breaksw
			case 48:
				sudo sysctl hw.acpi.video.lcd0.brightness=55
				breaksw
			case 55:
				sudo sysctl hw.acpi.video.lcd0.brightness=61
				breaksw
			case 61:
				sudo sysctl hw.acpi.video.lcd0.brightness=71
				breaksw
			case 71:
				sudo sysctl hw.acpi.video.lcd0.brightness=80
				breaksw
			case 80:
				sudo sysctl hw.acpi.video.lcd0.brightness=100
				breaksw
			case 100:
				sysctl hw.acpi.video.lcd0.brightness
				breaksw
			default:
				breaksw
		endsw
	breaksw	
	default:
		echo "No arguments given. Usage: brightness [up | down]"
	breaksw
endsw
endif
 
Oh, and that quote was from a visitor message on my page, I posted it here (admin, if that's not okay, please remove, sorry I didn't even think about it!)
 
Back
Top