Total Pageviews

Sunday, April 6, 2014

ចង់ដឹង Devices ណាខ្លះដែលភ្ជាប់ទៅកាន់ System

System.getInputDevices()វានឹង​ fetches គ្រប់ទាំង input devices ដែលភ្ជាប់ទៅនឹង system ដូចជា touchscreen, keyboard, mouse joystic។ សំរាប់ input devices ដែលធ្លាប់ភ្ជាប់ម្តងហើយប៉ុន្តែ មិនត្រូវបានភ្ជាប់ហើយហ្វាំងសិនវាមិនត្រូវបាន​returned
សំរាប់ហ្វាំងសិននេះគឺប្រើនៅពេលដែល application ចាប់ផ្តើមដំណើរការ ហើយនឹង resumed វាវិញ។ អំឡុងពេលដំណើរការ សូមប្រើ inputDeviceStatus event ជំនួសដោយការ get raised នៅពេល New input devices ត្រូ​វបានភ្ជាប់ទៅនឹង SYSTEM នៅពេល devices ដែលមានហើយមិនត្រូវបានភ្ជាប់ ហើយនឹងត្រូវភា្ជាប់ឡើងវិញ

Syntax: system.getInputDevices()

Return value: សំរាប់ input device information គឺគ្រាន់តែផ្តល់លើ android តែប៉ុណ្ណោះ
សំរាប់ IOS, Mac windows មិន Support input devices ទេ
សូមមើលកូដះ
-- Fetch all input devices currently connected to the system.
local inputDevices = system.getInputDevices()
-- Print all of the input devices found to the log.
if #inputDevices > 0 then
    print("Input Devices Found:")
    for index = 1, #inputDevices do
        print("- " .. inputDevices[index].displayName)
    end
else
    print("No input devices found.")

end

No comments:

Post a Comment