带有 C# 的 Dualshock 4 触摸板

Posted

技术标签:

【中文标题】带有 C# 的 Dualshock 4 触摸板【英文标题】:Dualshock 4 Touch Pad with C# 【发布时间】:2014-01-30 09:36:21 【问题描述】:

我一直在玩一些 DS4 及其在 PC 上的交互。 到目前为止,我已经有了一个按钮列表和所有轴。

现在我期待的问题是,有没有办法访问触摸板(而不是按钮)。 Aka,我可以检查触摸板的某个 X/Y 是否被触摸吗? 如果有,怎么做?

我正在使用 SlimDX。

【问题讨论】:

【参考方案1】:

我是用 Swift 做的,但是 USB 报告索引是一样的。 您应该能够将其翻译成 C#。棘手的部分是读取字节并将它们转换为整数 16。

触摸板支持同时使用两个手指,因此如果您想稍后处理手势,则需要以某种方式跟踪触摸 ID。

下面的代码只读取它可以在单个报告中发送的 4 个数据包中的 1 个。

let bluetoothOffset = self.isBluetooth ? 2 : 0

// trackpad can send up to 4 packets per report
// it is sampled at a higher frequency than the reports
let numberOfPackets = report[33 + bluetoothOffset] // 1 to 4
// report[34 + bluetoothOffset] // not sure what this is, packet counter maybe?
self.touchpadTouch0IsActive = report[35 + bluetoothOffset] & 0b1000_0000 != 0b1000_0000

if self.touchpadTouch0IsActive 
    self.touchpadTouch0Id = report[35 + bluetoothOffset] & 0b0111_1111
    // 12 bits only
    self.touchpadTouch0X = Int16((UInt16(report[37 + bluetoothOffset]) << 8 | UInt16(report[36 + bluetoothOffset]))      & 0b0000_1111_1111_1111)
    self.touchpadTouch0Y = Int16((UInt16(report[38 + bluetoothOffset]) << 4 | UInt16(report[37 + bluetoothOffset]) >> 4) & 0b0000_1111_1111_1111)


self.touchpadTouch1IsActive = report[39 + bluetoothOffset] & 0b1000_0000 != 0b1000_0000 // if not active, no need to parse the rest
if self.touchpadTouch1IsActive 
    self.touchpadTouch1Id = report[39 + bluetoothOffset] & 0b0111_1111
    // 12 bits only
    self.touchpadTouch1X = Int16((UInt16(report[41 + bluetoothOffset]) << 8 | UInt16(report[40 + bluetoothOffset]))      & 0b0000_1111_1111_1111)
    self.touchpadTouch1Y = Int16((UInt16(report[42 + bluetoothOffset]) << 4 | UInt16(report[41 + bluetoothOffset]) >> 4) & 0b0000_1111_1111_1111)

点击在报告的单独部分中读取。

self.touchpadButton = report[7 + bluetoothOffset] & 0b0000_0010 == 0b0000_0010

完整代码在我的仓库中,尽管 IMU 和电池部分尚未完成:https://github.com/MarcoLuglio/ds4mac/blob/master/GamePad/DualShock4Controller.swift

同时检查https://www.psdevwiki.com/ps4/DualShock_4 它提到了以下可能对您有用的规范:

尺寸 52mmx23mm(外部约) 分辨率:型号 CUH-ZCT1x 系列(零售)1920x943(44.86 点/毫米)

【讨论】:

以上是关于带有 C# 的 Dualshock 4 触摸板的主要内容,如果未能解决你的问题,请参考以下文章

使用兼容电源造成苹果mac触摸板呆滞的原因?

宏碁笔记本触摸板失灵如何解决?

mac触摸板按下不清脆了

电脑触摸屏排线松动怎么维修 电脑触摸板使用技巧

笔记本触摸板如何用鼠标右键?

苹果电脑装win10触摸板不能用是怎么回事