-
Notifications
You must be signed in to change notification settings - Fork 0
/
miix_fnfix.py
executable file
·57 lines (41 loc) · 1.45 KB
/
miix_fnfix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2018 Kevin Ottens <ervin@ipsquad.net>
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
from argparse import ArgumentParser
import usb.core
import usb.util
reattach_needed = False
def claim_device(device, interface):
global reattach_needed
if device.is_kernel_driver_active(interface):
reattach_needed = True
device.detach_kernel_driver(interface)
usb.util.claim_interface(device, interface)
def release_device(device, interface):
usb.util.release_interface(device, interface)
if reattach_needed:
device.attach_kernel_driver(interface)
if __name__ == "__main__":
arg_parser = ArgumentParser(description="A tool for forcing fnlock mode on Lenovo MIIX keyboards")
arg_parser.add_argument("-u", "--unlock", action='store_true', help="Unlocks")
args = arg_parser.parse_args()
# Find the MIIX keyboard
device = usb.core.find(idVendor=0x17ef, idProduct=0x60bb)
if device is None:
raise ValueError('No MIIX keyboard attached to this system')
interface = 0x01
claim_device(device, interface)
value = 0x02
if (args.unlock):
value = 0x01
try:
device.ctrl_transfer(0x21, 0x09, 0x0209, interface, bytes([0x09, 0x54, value]))
except:
release_device(device, interface)
raise
release_device(device, interface)