Monday, December 28, 2015

Use Python to enable Bluetooth PAN in Windows

We cannot enable Windows Bluetooth PAN by a program because Windows doesn't public the Bluetooth PAN API that is implemented in bthpanapi.dll. I find a way to enable it by a script method, Python. The idea comes from UI automatic test.

Download and install Python 3.5.1

Install Pillow and PyAutoGUI in Python.
>pip install Pillow
>pip install PyAutoGUI

The Python program to enable Windows Bluetooth PAN is as below.


import os                                            
import pyautogui                                     
                                                     
os.system ("control printers")                       
                                                     
while (True):                                        
    Location = pyautogui.locateOnScreen('VIBEZ.png') 
    if (Location != None):                           
        break                                        
pyautogui.rightClick (Location [0], Location [1])    
                                                     
x = Location [0] + 10                                
y = Location [1] + 83                                
pyautogui.click (x, y)                               
                                                     
x += 230                                             
pyautogui.click (x, y)                               

The code opens "Devices and Printers" of Windows Control Panel.

os.system ("control printers")



The code moves the mouse cursor to the icon of "VIBE Z" and click the right button of the mouse to display menu items.

while (True):                                       
    Location = pyautogui.locateOnScreen('VIBEZ.png')
    if (Location != None):                          
        break                                       
pyautogui.rightClick (Location [0], Location [1])   



The code moves the mouse cursor to the 4th menu item.

x = Location [0] + 10  
y = Location [1] + 83  
pyautogui.click (x, y) 






The code moves the mouse cursor to the right menu item to enable Bluetooth PAN.

x += 230               
pyautogui.click (x, y) 




-Count



No comments:

Post a Comment