IBM Thinkpad Hardware Control

The ‘Access IBM’ button on my laptop doesn’t get much use, so I decided to map it up to the PC release of XBMC (Xbox Media Centre). That’s the easy part, because you either set that in the registry, or use this small app.

When XBMC fires up I’d also like to set the volume levels of the laptop so that they output properly for the AV equipment I’ve got hooked into it. Once XMBC shuts down I’ll set back down so that the sound is at a lower level. The IBM laptops use a hardware volume control (independent to the Windows volume control) so I’m using some Python scripts to access the IBM hardware.

Here’s the finished scripts (the first one calls the second):


Set WshShell = WScript.CreateObject("WScript.Shell")

'Set windows volume level
SetSoundLevel 90

'Set IBM ThinkPad volume level
ReturnCode  = WshShell.Run("C:\win32app\startup\thinkpadsetvolume.pyw 14", 1, true)

'Run XBMC and wait until it exits
ReturnCode  = WshShell.Run("C:\Progra~1\XBMC\XBMC.exe -fs -p", 1, true)

'Set IBM ThinkPad volume level
ReturnCode  = WshShell.Run("C:\win32app\startup\thinkpadsetvolume.pyw 3", 1, true)

'Set windows volume level
'SetSoundLevel 30

' ------------------------------------------------------------------------
' Function to set the Windows sound level
' ------------------------------------------------------------------------
Sub SetSoundLevel ( iMyLevel )

On Error Resume Next

Dim blSoundDevicePresent
Dim objSoundDevice

blSoundDevicePresent = False

For Each objSoundDevice In GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf ("Win32_SoundDevice")
 blSoundDevicePresent = True
 Exit For

If Not blSoundDevicePresent Then Exit Sub

Dim iDefaultLevel, iSoundLevel, objSoundLevel

iDefaultLevel = 5

If Not IsNumeric ( iMyLevel ) Then iMyLevel = iDefaultLevel

MyLevel = CInt ( iMyLevel )
If Err.number  0 Then iMyLevel = iDefaultLevel

If iMyLevel  100 Then iMyLevel = iDefaultLevel

set objSoundLevel = CreateObject ( "SetSoundLevel.SoundLevel" )
If Err.number  0 Then Exit Sub

iSoundLevel = iMyLevel * ( objSoundLevel.GetMaxSoundLevel - objSoundLevel.GetMinSoundLevel ) / 100

objSoundLevel.SetSoundLevel iSoundLevel

set objSoundLevel = Nothing

End Sub


import thinkpad
import time
import sys

if __name__ == '__main__':
        c = int(sys.argv[1])
    except IndexError:
        c = 14
    hk = thinkpad.Hotkeys()

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s