Updated X-keys for PowerShell

I have created a new version that provides some better options for event arguments.

You can now key the key number and Unit ID as Integers within the event handler function. The original string value is still there also.

The new values are:

  • $event.sourceEventArgs.KeyID
  • $event.sourceEventArgs.UnitID

This makes it easier to use a Switch statement for the unit ID so you can deal with multiple X-Keys and have different actions on the same key ID’s.

Example script to show the UnitID and KeyID for the KeyPressed event

<br data-mce-bogus="1">

add-type -path 'C:\Users\imorrish\onedrive\powershell\x-keys\VISE_Xkeys.dll'
$PIE = new-object VISE_Xkeys.xkeys
$keys = $PIE.GetDevices()
$keys #Get the Unit ID's from this output and create a NewDevice for each

$pie.NewDevice(0)
$pie.NewDevice(3)

function HandleXkey($key, $device) 
{
    write-host $key $device
}
$MyEvent = Register-ObjectEvent -InputObject $Pie -EventName KeyPressed -SourceIdentifier KeyPressed -Action {HandleXkey($event.sourceEventArgs.KeyID,$event.sourceEventArgs.UnitID)}

If you add another X-keys device once the script is running, just run

$PIE.GetDevices()

and $pie.NewDevices(xxx)

where xxx is the ID of the new device, and it will be included in the existing event notification.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s