🎹 rbnput-darwin-minimal 🍎
ไลบรารี Ruby ขนาดเล็กสำหรับตรวจจับการกดแป้นพิมพ์บนระบบ macOS โดยใช้ FFI เชื่อมต่อกับ system library ของ Darwin โดยตรง
✨ คุณสมบัติ
- 🔍 ตรวจจับการกดคีย์แบบ low-level
- 🧬 ใช้ FFI เชื่อมต่อกับ Carbon / IOKit
- 🪶 ไม่มี dependency หนัก
- 📦 โค้ดสั้นและเข้าใจง่าย เหมาะสำหรับเรียนรู้หรือฝังใช้งานในโปรเจคเล็กๆ
🚀 ตัวอย่างเริ่ม Listener เพื่อรับ keycode
require "rbnput"
listener = Rbnput::Listener.new
listener.on_press do |key|
puts "Key up : #{key}"
end
listener.on_release do |key|
puts "Key down : #{key}"
end
listener.start
listener.join🖥️ การรันแบบ Shell
💎 ใช้ ruby ตรงๆ
APP_MODE=local ruby ./examples/keyboard_listener.rb🧰 ใช้ rake
# สำหรับทดสอบ local lib
rake test_local# สำหรับทดสอบ production gem
rake test_local⚠️ ข้อจำกัด - 🐧 รองรับเฉพาะ macOS (Darwin) - 💎 ต้องรันบน Ruby ที่รองรับ ffi - 🔐 ต้องมีสิทธิ์ “Input Monitoring” ใน System Settings
🔑 การให้สิทธิ์ (Permissions) 1. ⚙️ เปิด System Settings 2. 🔐 ไปที่ Privacy & Security 3. ⌨️ เลือก Input Monitoring 4. ➕ เพิ่ม Ruby หรือ Terminal ที่ใช้รันโปรแกรมของคุณเข้าไป
📂 โฟลเดอร์ / ไฟล์สำคัญ
- ./lib/rbnput/darwin_listener.rb | Most Of Implement 🧠
- ./lib/rbnput.rb | Lib Endpoint
- ./lib/rbnput/key_code_const.rb | All Key Map
- ./lib/rbnput/key_code.rb | Class KeyCode(vk, is_media)
- ./lib/rbnput/darwin_ffi.rb | SystemLibrary Bind FFI 🪪
- ./lib/rbnput/simple_mutex_thread.rb | Boring Thread Implement