Using The Sony Vaio Jogwheel With Perl

25. September 2003, by

This is my half-assed documentation about using the jog-wheel on a Sony Vaio notebook with a perl script. Example included below, your mileage may vary.



To use the jog wheel at all, you need to load the driver module "sonypi". It's included in newer kernel versions, so probably all you have to do is to load it using modprobe, or to add something like this to your modules.conf file:

alias char-major-10-250 sonypi options sonypi minor=250 useinput=0 verbose=0 It seems that the module itself already maps the wheel to emulate a scroll mouse in X by default; the "useinput=0" options disables this. In English: If you don't disable "useinput", in addition to the actions you define in your perl script, your front window will probably scroll when you use the wheel.

You may need to create the appropriate device file in /dev/ using the same minor number as in your modules.conf options: mknod /dev/sonypi c 10 250 Now, with the module loaded and the device present, you're all set to go.

Getting Values from /dev/sonypi

Just for kicks, do a cat /dev/sonypi and wiggle the wheel. You should see bytes appear in your terminal. We're going to read and interpret these using a simple perl script now.

Interpreting the values

I didn't bother reading the sonypi documentation much, and I didn't see the logic behind the values (bitmask?) in relation to the wheel-actions, so I just hard-coded the return values in the script and added subroutines to call when any of these actions occur.

Possible actions you get from the wheel:

  • Button press
  • Button release
  • Scroll in either direction, slow, fast or very fast
  • Scroll with buttton pressed, in either direction, slow, fast or very fast

Example Script

The following script reads the wheel actions from /dev/sonypi and just reports back to you what's happening:


$dev = "/dev/sonypi";

open (F, $dev);
while (1) {
$char = getc F;
$num = ord($char);

($num == 1) && do { &scroll("down","slow"); last CASE; };
($num == 42) && do { &scroll("down","fast"); last CASE; };
($num == 46) && do { &scroll("down","veryfast"); last CASE; };

($num == 2) && do { &scroll("up","slow"); last CASE; };
($num == 43) && do { &scroll("up","fast"); last CASE; };
($num == 47) && do { &scroll("up","veryfast"); last CASE; };

($num == 3) && do { &scrollpress("down","slow"); last CASE; };
($num == 44) && do { &scrollpress("down","fast"); last CASE; };
($num == 48) && do { &scrollpress("down","veryfast"); last CASE; };

($num == 4) && do { &scrollpress("up","slow"); last CASE; };
($num == 45) && do { &scrollpress("up","fast"); last CASE; };
($num == 49) && do { &scrollpress("up","veryfast"); last CASE; };

($num == 5) && do { &press(); last CASE; };
($num == 56) && do { &release(); last CASE; };
print "Unknown event ($num)

close F;

sub scroll {
(my $dir, my $speed) = @_;
print "Scrolled $dir, $speed

sub scrollpress {
(my $dir, my $speed) = @_;
print "Scrolled (while pressed) $dir, $speed

sub press {
print "Pressed button

sub release {
print "Released button

There you go. The four subroutines at the end of the script is where you fill in the things you want to happen. To see what I use on my Vaio, check this out (pressing the button opens xterm, scrolling sets screen brightness). If I ever get round to do something pop-up-ish open pressing the button, I'll post it here.


This is just a quick ugly hack to get the wheel to do something. There is a number of real software projects providing an API to tame the wheel.. check those out if you don't want to roll your own stuff in perl. But then again, why not tinker away for a bit with your favourite script language :-) ...



Login | Current user: Guest | Elapsed: 0.025165 seconds. Requests: 8. Average: 0.42602075