{"id":3551,"date":"2025-04-17T23:54:36","date_gmt":"2025-04-17T15:54:36","guid":{"rendered":"https:\/\/saludpcb.com\/zh\/?p=3551"},"modified":"2025-09-26T06:15:44","modified_gmt":"2025-09-25T22:15:44","slug":"list-macos-hid-devices-with-python","status":"publish","type":"post","link":"https:\/\/saludpcb.com\/zh\/list-macos-hid-devices-with-python\/","title":{"rendered":"2025 \u5c0b\u627e macOS HID \u5225\u518d\u6d6a\u8cbb\u6642\u9593 ! \u7528 Python \u8b93\u4f60\u79d2\u5217\u51fa\u6240\u6709\u88dd\u7f6e"},"content":{"rendered":"\n<hr class=\"wp-block-separator alignwide has-text-color has-palette-color-1-color has-alpha-channel-opacity has-palette-color-1-background-color has-background is-style-wide\"\/>\n\n\n\n<p><strong>macOS HID ! <\/strong>\u4f60\u662f\u5426\u66fe\u7d93\u60f3\u904e\u8981\u6293\u51fa\u4f60\u96fb\u8166\u4e0a\u63a5\u4e86\u54ea\u4e9b\u88dd\u7f6e\uff1f\u50cf\u662f\u9375\u76e4\u3001\u6ed1\u9f20\u3001\u904a\u6232\u624b\u628a\uff0c\u751a\u81f3\u662f\u4e00\u4e9b\u7279\u6b8a\u7528\u9014\u7684\u8a2d\u5099\uff0c\u4f8b\u5982\u689d\u78bc\u6383\u63cf\u5668\u6216 RFID \u8b80\u5361\u5668\uff0c\u5176\u5be6\u90fd\u5c6c\u65bc HID\uff08Human Interface Device\uff09\u88dd\u7f6e\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u5e36\u4f60\u4e00\u6b65\u4e00\u6b65\u5730\u4f7f\u7528 Python\uff0c\u5728 macOS \u7cfb\u7d71\u4e0a\u5217\u51fa\u9019\u4e9b HID \u88dd\u7f6e\uff0c\u4e26\u5728 Visual Studio Code (VSCode) \u74b0\u5883\u4e2d\u9032\u884c\u958b\u767c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2025\/04\/2025-macOS-HID.jpg\" alt=\"macOS HID\" class=\"wp-image-3561\" title=\"\" srcset=\"https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2025\/04\/2025-macOS-HID.jpg 1024w, https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2025\/04\/2025-macOS-HID-768x768.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>\u5167\u5bb9<\/h2><nav><ul><li class=\"\"><a href=\"#\u4ec0\u9ebc\u662f-modbus\uff1f\">\u4ec0\u9ebc\u662f HID\uff1f<\/a><\/li><li class=\"\"><a href=\"#pwm-\u8207\u547c\u5438\u71c8\u539f\u7406\u5feb\u901f\u7406\u89e3\">\u70ba\u4ec0\u9ebc\u7528 Python\uff1f<\/a><\/li><li class=\"\"><a href=\"#-1\">\u8a2d\u5b9a\u74b0\u5883<\/a><\/li><li class=\"\"><a href=\"#\u74b0-1\">\u5b89\u88dd Python \u5957\u4ef6\u8207\u5de5\u5177<\/a><\/li><li class=\"\"><a href=\"#\u5c08\u6848\u7d50\u69cb\">\u4f7f\u7528 VSCode \u5efa\u7acb\u5c08\u6848<\/a><\/li><li class=\"\"><a href=\"#\u4f7f\u7528-esp-idf-\u64b0\u5beb\u547c\u5438\u71c8\u63a7\u5236\u7a0b\u5f0f\">\u7a0b\u5f0f\u78bc<\/a><\/li><li class=\"\"><a href=\"#\u7de8\u8b6f\u548c\u71d2\u9304\">\u7a0b\u5f0f\u78bc\u89e3\u8aaa<\/a><\/li><li class=\"\"><a href=\"#\u7de8\u8b6f\u548c\u71d2\u9304-1\">macOS HID \u6240\u6709\u88dd\u7f6e<\/a><\/li><li class=\"\"><a href=\"#\u7d50\u8ad6\">\u7d50\u8ad6<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4ec0\u9ebc\u662f-modbus\uff1f\">\u4ec0\u9ebc\u662f HID\uff1f<\/h2>\n\n\n\n<p>HID\uff08Human Interface Device\uff09\u662f\u4e00\u7a2e USB \u88dd\u7f6e\u985e\u578b\uff0c\u8a2d\u8a08\u4f86\u8207\u4eba\u4e92\u52d5\u3002\u5e38\u898b\u7684 HID \u88dd\u7f6e\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9375\u76e4<\/li>\n\n\n\n<li>\u6ed1\u9f20<\/li>\n\n\n\n<li>\u89f8\u63a7\u7b46\/\u624b\u5beb\u677f<\/li>\n\n\n\n<li>\u904a\u6232\u63a7\u5236\u5668<\/li>\n\n\n\n<li>\u67d0\u4e9b\u611f\u61c9\u5668\u3001RFID \u95b1\u8b80\u5668<\/li>\n<\/ul>\n\n\n\n<p>\u9019\u985e\u88dd\u7f6e\u6709\u500b\u7279\u6027\uff0c\u5c31\u662f\u4e0d\u9700\u8981\u5b89\u88dd\u984d\u5916\u9a45\u52d5\u7a0b\u5f0f\uff0c\u7cfb\u7d71\u672c\u8eab\u5c31\u80fd\u8fa8\u8b58\u4e26\u652f\u63f4\u5b83\u5011\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pwm-\u8207\u547c\u5438\u71c8\u539f\u7406\u5feb\u901f\u7406\u89e3\">\u70ba\u4ec0\u9ebc\u7528 Python\uff1f<\/h2>\n\n\n\n<p>Python \u662f\u4e00\u500b\u7c21\u6f54\u3001\u6613\u5b78\u53c8\u6709\u5f37\u5927\u5957\u4ef6\u751f\u614b\u7cfb\u7684\u8a9e\u8a00\u3002\u4f7f\u7528 Python \u64cd\u4f5c HID \u88dd\u7f6e\u6709\u4ee5\u4e0b\u512a\u52e2\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>hidapi<\/code> \u5957\u4ef6\u652f\u63f4\u8de8\u5e73\u53f0\uff08Windows\u3001Linux\u3001macOS\uff09<\/li>\n\n\n\n<li>\u53ea\u9700\u5e7e\u884c\u7a0b\u5f0f\u78bc\u5c31\u80fd\u5feb\u901f\u8b80\u53d6\u88dd\u7f6e\u6e05\u55ae<\/li>\n\n\n\n<li>\u9069\u5408\u5feb\u901f\u539f\u578b\u958b\u767c\u8207\u81ea\u52d5\u5316\u6e2c\u8a66<\/li>\n\n\n\n<li>\u5982\u679c\u4f60\u662f\u958b\u767c\u8005\u3001Maker\uff0c\u751a\u81f3\u53ea\u662f\u55ae\u7d14\u5c0d\u786c\u9ad4\u6709\u8208\u8da3\u7684\u4eba\uff0cPython \u662f\u4e00\u500b\u975e\u5e38\u68d2\u7684\u8d77\u9ede\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"-1\">\u8a2d\u5b9a\u74b0\u5883<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/www.python.org\" target=\"_blank\" rel=\"noopener\">\u5b89\u88dd Python 3.x or \u66f4\u9ad8<\/a>\u3002<\/strong><\/li>\n\n\n\n<li><strong>\u7d42\u7aef\u6216\u547d\u4ee4\u884c\u5de5\u5177\u4e26\u53ef\u57f7\u884c Python \u8173\u672c\u3002<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u74b0-1\">\u5b89\u88dd <a href=\"https:\/\/saludpcb.com\/zh\/python-3-x-quick-install-start\/\">Python<\/a> \u5957\u4ef6\u8207\u5de5\u5177<\/h2>\n\n\n\n<p>\u5728\u958b\u59cb\u7de8\u7a0b\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u5df2\u5b8c\u6210\u4ee5\u4e0b\u6e96\u5099\u5de5\u4f5c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">brew install hidapi         # Install the C-level hidapi library\npip install hidapi          # Install the Python bindings<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5c08\u6848\u7d50\u69cb\">\u4f7f\u7528 VSCode \u5efa\u7acb\u5c08\u6848<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5efa\u7acb\u8cc7\u6599\u593e\uff0c\u4f8b\u5982 <code>hid_scanner<\/code><\/li>\n\n\n\n<li>\u5728 VSCode \u4e2d\u958b\u555f\u8a72\u8cc7\u6599\u593e<\/li>\n\n\n\n<li>\u65b0\u589e <code>list_hid_devices.py<\/code> \u6a94\u6848<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4f7f\u7528-esp-idf-\u64b0\u5beb\u547c\u5438\u71c8\u63a7\u5236\u7a0b\u5f0f\">\u7a0b\u5f0f\u78bc<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u5b8c\u6574\u7a0b\u5f0f\u78bc :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">import hid\n\ndef list_hid_devices():\n    devices = hid.enumerate()\n    if not devices:\n        print(\"No HID devices found.\")\n        return\n\n    for idx, device in enumerate(devices):\n        print(f\"Device {idx + 1}:\")\n        print(f\"  Vendor ID: {hex(device['vendor_id'])}\")\n        print(f\"  Product ID: {hex(device['product_id'])}\")\n        print(f\"  Manufacturer: {device.get('manufacturer_string')}\")\n        print(f\"  Product: {device.get('product_string')}\")\n        print(f\"  Serial Number: {device.get('serial_number')}\")\n        print(f\"  Path: {device['path'].decode('utf-8') if isinstance(device['path'], bytes) else device['path']}\")\n        print(f\"  Interface Number: {device.get('interface_number')}\")\n        print(\"-\" * 40)\n\nif __name__ == \"__main__\":\n    list_hid_devices()\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7de8\u8b6f\u548c\u71d2\u9304\">\u7a0b\u5f0f\u78bc\u89e3\u8aaa<\/h2>\n\n\n\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u7684\u91cd\u9ede\u5728\u65bc\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>hid.enumerate()<\/code> \u53d6\u5f97\u6240\u6709\u9023\u63a5\u7684 HID \u88dd\u7f6e\u6e05\u55ae<\/li>\n\n\n\n<li>\u5229\u7528 <code>for<\/code> \u8ff4\u5708\u9010\u4e00\u5217\u51fa\u88dd\u7f6e\u8cc7\u8a0a<\/li>\n\n\n\n<li><code>vendor_id<\/code> \u548c <code>product_id<\/code> \u662f\u7528\u4f86\u8fa8\u8b58\u88dd\u7f6e\u7684\u57fa\u672c\u53c3\u6578<\/li>\n\n\n\n<li><code>manufacturer_string<\/code> \u548c <code>product_string<\/code> \u901a\u5e38\u5305\u542b\u88dd\u7f6e\u54c1\u724c\u8207\u540d\u7a31<\/li>\n\n\n\n<li><code>path<\/code> \u662f\u88dd\u7f6e\u7684\u5167\u90e8\u8fa8\u8b58\u8def\u5f91\uff0c\u8207\u8b80\u5beb\u88dd\u7f6e\u6642\u6709\u95dc<\/li>\n<\/ul>\n\n\n\n<p>\u9019\u4e9b\u8cc7\u8a0a\u80fd\u5e6b\u4f60\u5feb\u901f\u77ad\u89e3\u76ee\u524d\u7cfb\u7d71\u4e0a\u6709\u54ea\u4e9b HID \u88dd\u7f6e\u63a5\u5165\uff0c\u4e26\u53ef\u4f5c\u70ba\u5f8c\u7e8c\u901a\u8a0a\u6216\u63a7\u5236\u7684\u4f9d\u64da\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7de8\u8b6f\u548c\u71d2\u9304-1\">macOS HID \u6240\u6709\u88dd\u7f6e<\/h2>\n\n\n\n<p>\u4e0b\u9762\u662f\u5728 macOS \u4e0a\u57f7\u884c <code>list_hid_devices.py<\/code> \u7684\u8f38\u51fa\u53ef\u80fd\u7684\u7d50\u679c\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">Device 1:\n  Vendor ID       : 0x05ac\n  Product ID      : 0x0250\n  Manufacturer    : Apple Inc.\n  Product         : Apple Internal Keyboard \/ Trackpad\n  Serial Number   : XYZ1234567\n  Path            : IOService:\/AppleACPIPlatformExpert\/...\n  Interface Number: 0\n----------------------------------------\nDevice 2:\n  Vendor ID       : 0x046d\n  Product ID      : 0xc534\n  Manufacturer    : Logitech\n  Product         : USB Receiver\n  Serial Number   : None\n  Path            : IOService:\/AppleUSB20HubPort@1a000000\/...\n  Interface Number: 1\n----------------------------------------\nDevice 3:\n  Vendor ID       : 0x1a2b\n  Product ID      : 0x1f2e\n  Manufacturer    : Generic Manufacturer\n  Product         : RFID Reader\n  Serial Number   : A1B2C3D4E5\n  Path            : IOService:\/AppleUSB20HubPort@1d000000\/...\n  Interface Number: 2\n----------------------------------------<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7d50\u8ad6\">\u7d50\u8ad6<\/h2>\n\n\n\n<p>\u900f\u904e Python \u642d\u914d <code>hidapi<\/code>\uff0c\u4f60\u53ef\u4ee5\u5f88\u8f15\u9b06\u5730\u5217\u51fa\u4e26\u6aa2\u67e5\u6240\u6709 HID \u88dd\u7f6e\uff0c\u9019\u5c0d\u65bc\u958b\u767c\u786c\u9ad4\u61c9\u7528\u3001\u9664\u932f\u8a2d\u5099\u9023\u63a5\uff0c\u751a\u81f3\u505a\u81ea\u52d5\u5316\u6e2c\u8a66\u90fd\u6709\u6975\u5927\u7684\u5e6b\u52a9\u3002\u5c24\u5176\u662f\u5728 macOS \u4e0a\uff0c\u4e0d\u9700\u8981\u88dd\u4efb\u4f55\u9a45\u52d5\uff0c\u5c31\u53ef\u4ee5\u8dd1\u8d77\u4f86\u3002<\/p>\n\n\n\n<p>\u4e0b\u4e00\u6b65\u4f60\u53ef\u4ee5\u5617\u8a66\u9032\u4e00\u6b65 <strong>\u8207 HID \u88dd\u7f6e\u6e9d\u901a\uff08\u8b80\u5beb\u8cc7\u6599\uff09<\/strong>\uff0c\u751a\u81f3\u7528 GUI \u5efa\u7acb\u7c21\u55ae\u63a7\u5236\u9762\u677f\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator alignwide has-text-color has-palette-color-1-color has-alpha-channel-opacity has-palette-color-1-background-color has-background is-style-wide\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>macOS HID ! \u4f60\u662f\u5426\u66fe\u7d93\u60f3\u904e\u8981\u6293\u51fa\u4f60\u96fb\u8166\u4e0a\u63a5\u4e86\u54ea\u4e9b\u88dd\u7f6e\uff1f\u50cf\u662f\u9375\u76e4\u3001\u6ed1\u9f20\u3001\u904a\u6232\u624b\u628a\uff0c\u751a\u81f3\u662f\u4e00\u4e9b\u7279\u6b8a\u7528\u9014 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3561,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[27,21,44,9,11],"class_list":["post-3551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-c","tag-ide","tag-programming-language","tag-python","tag-tutorial"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/3551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/comments?post=3551"}],"version-history":[{"count":7,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/3551\/revisions"}],"predecessor-version":[{"id":3562,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/3551\/revisions\/3562"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/media\/3561"}],"wp:attachment":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/media?parent=3551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/categories?post=3551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/tags?post=3551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}