我的征尘是星辰大海。。。
The dirt and dust from my pilgrimage forms oceans of stars...
-------当记忆的篇章变得零碎,当追忆的图片变得模糊,我们只能求助于数字存储的永恒的回忆
作者:黄教授
手机视频列表
看似最平凡的键盘鼠标背后藏着底层编程真相
视频
音频
原始脚本
看似最平凡的键盘鼠标,原来藏着我们都忽略的底层真相。 CH340加CH9329硬件输入中文踩坑实录。 最近玩了一套 CH340加CH9329 硬件键鼠模拟设备,本来我真的以为这是一件再简单不过的小事。 插上线,发几条指令,让系统以为有人在敲键盘、点鼠标,不就轻轻松松搞定了吗?尤其是输入中文这种天天都在做的事情,谁会想到里面居然藏着一堆平时根本不会注意到的坑。 可真正从头到尾跑通一遍之后,我反而生出了很多很真实的感慨。 也忽然发现,我们每天用的最熟练、最普通的键盘鼠标,其实大多数人根本没有真正理解过它底层到底是怎么一回事。 一开始上手的时候,我还带着一种很想当然的心态,觉得这种基础输入设备能有多复杂?结果第一段代码跑下去就直接翻车了。 鼠标点下去之后就再也弹不起来,键盘按完之后就一直处于卡死的状态,整个界面乱跳,按键失灵,怎么救都救不回来。 后来才真正弄明白一件最基础却又最容易被忽略的事情。 我们平时手按一下鼠标,敲一下键盘,看起来只是一个动作。 可在系统和硬件的底层逻辑里,按下和释放是两个完全独立的事件,人自然会松手。 但机器模拟必须把两个动作都完整做一遍,少一个都会让系统误以为按键一直按住,最后直接卡死。 这件小事虽然简单,却一下子把我那种随便写写就能跑的心态彻底打醒了。 更让我颠覆认知的是中间关于中文输入的一段弯路。 最开始我也跟绝大多数人一样,被长期的使用习惯带着走,理所当然的觉得想要输入中文,就必须安装中文输入法,不然系统根本不可能识别汉字。 甚至还想过去模拟拼音、模拟选词这种完全绕远路的方式。 可一路往底层追问下去才发现,自己完全被上层的使用习惯给骗了。 现代操作系统早就原生支持 Unicode,任何语言、任何文字,在系统底层都只是一串对应的编码。 系统本身就可以直接识别并显示,和你有没有安装中文输入法没有任何关系。 输入法其实只是给人类使用的一层翻译工具,并不是系统运行的必要条件。 这件事也让我忽然意识到,很多我们以为天经地义的常识,其实只是长期使用形成的习惯,并不是底层真正的规则。 等到真正明白可以用 Unicode 的直接输入中文之后我又以为这下总该顺利了。 不就是按一个 Ctrl 加 Shift 加 U 的组合键,输入编码再回车就完事了吗?可现实是代码跑了一遍又一遍,系统始终只输出一串普通的字母和数字,完全不把它当成汉字处理。 后来才搞清楚,组合键这种东西真的没有我们想象的那么随便,时序上差一点点系统就完全不识别。 我们手动操作的时候,明明是先按住 Ctrl 加 Shift,按一下 U,看到下划线出现之后,就立刻松开修饰键,再正常输入编码。 最后回车确认,根本不可能一直按住 Ctrl 加 Shift 去输字母数字。 代码能跑通的关键,也只是精准模拟了这一段真实的操作节奏,而不是像很多人误解的那样,一直按住修饰键不放。 就这么一点点细微的差别,对了就通,不对就完全失效。 也让我第一次认真意识到,我们天天按的组合键背后其实有一套非常严谨的逻辑。 最后还有一个小麻烦,就是系统开启中文输入法的时候,会对 Unicode 的输入产生干扰,按键会被输入法拦截到选词框里,导致输出乱码。 而我们做的是非侵入式的硬件模拟,不能去修改对方电脑的设置,也不能安装任何软件,所以只能依靠硬件指令的方式提前清理状态,避开干扰,输入完成之后再恢复原状,全程不留下任何痕迹。 这也让我更加看明白一件事,中文输入法只是上层的一层包装,并不是底层输入必须遵守的规则。 真正稳定可靠的方式,反而是绕开这些上层工具,直接和系统底层对话。 整段经历走下来,其实技术难度并不算高,可给我的感触却特别深。 键盘和鼠标是每个人从第一次使用电脑就开始接触的东西,我们每天敲字点击,熟悉到不能再熟悉。 可真正理解底层逻辑的人其实并没有那么多。 有多少人知道按键是按下和释放两个事件?有多少人手动用过 Unicode 输入中文?有多少人想过没有输入法也能正常输出汉字?又有多少人真正理解组合键和输入法背后的原理?计算机发展到今天,界面越来越精致,功能越来越强大。 我们习惯了方便快捷的操作,却很少再去留意那些最基础、最底层、最朴素的东西。 这次踩坑让我最真实的感受就是,越平常越不起眼的东西,背后往往越不简单。 越是天天使用的基础功能,越值得我们静下心去看一眼它真正的样子。 很多时候不是事情本身有多难,而是我们太习惯想当然,忘了那些最根本的道理,其实一直都在最不起眼的地方。
修正脚本
看似最平凡的键盘鼠标,原来藏着我们都忽略的底层真相。 CH340加CH9329硬件输入中文踩坑实录。 最近玩了一套 CH340加CH9329 硬件键鼠模拟设备,本来我真的以为这是一件再简单不过的小事。 插上线,发几条指令,让系统以为有人在敲键盘、点鼠标,不就轻轻松松搞定了吗?尤其是输入中文这种天天都在做的事情,谁会想到里面居然藏着一堆平时根本不会注意到的坑。 可真正从头到尾跑通一遍之后,我反而生出了很多很真实的感慨。 也忽然发现,我们每天用的最熟练、最普通的键盘鼠标,其实大多数人根本没有真正理解过它底层到底是怎么一回事。 一开始上手的时候,我还带着一种很想当然的心态,觉得这种基础输入设备能有多复杂?结果第一段代码跑下去就直接翻车了。 鼠标点下去之后就再也弹不起来,键盘按完之后就一直处于卡死的状态,整个界面乱跳,按键失灵,怎么救都救不回来。 后来才真正弄明白一件最基础却又最容易被忽略的事情。 我们平时手按一下鼠标,敲一下键盘,看起来只是一个动作。 可在系统和硬件的底层逻辑里,按下和释放是两个完全独立的事件,人自然会松手。 但机器模拟必须把两个动作都完整做一遍,少一个都会让系统误以为按键一直按住,最后直接卡死。 这件小事虽然简单,却一下子把我那种随便写写就能跑的心态彻底打醒了。 更让我颠覆认知的是中间关于中文输入的一段弯路。 最开始我也跟绝大多数人一样,被长期的使用习惯带着走,理所当然地觉得想要输入中文,就必须安装中文输入法,不然系统根本不可能识别汉字。 甚至还想过去模拟拼音、模拟选词这种完全绕远路的方式。 可一路往底层追问下去才发现,自己完全被上层的使用习惯给骗了。 现代操作系统早就原生支持 Unicode,任何语言、任何文字,在系统底层都只是一串对应的编码。 系统本身就可以直接识别并显示,和你有没有安装中文输入法没有任何关系。 输入法其实只是给人类使用的一层翻译工具,并不是系统运行的必要条件。 这件事也让我忽然意识到,很多我们以为天经地义的常识,其实只是长期使用形成的习惯,并不是底层真正的规则。 等到真正明白可以用 Unicode 直接输入中文之后我又以为这下总该顺利了。 不就是按一个 Ctrl 加 Shift 加 U 的组合键,输入编码再回车就完事了吗?可现实是代码跑了一遍又一遍,系统始终只输出一串普通的字母和数字,完全不把它当成汉字处理。 后来才搞清楚,组合键这种东西真的没有我们想象的那么随便,时序上差一点点系统就完全不识别。 我们手动操作的时候,明明是先按住 Ctrl 加 Shift,按一下 U,看到下划线出现之后,就立刻松开修饰键,再正常输入编码。 最后回车确认,根本不可能一直按住 Ctrl 加 Shift 去输字母数字。 代码能跑通的关键,也只是精准模拟了这一段真实的操作节奏,而不是像很多人误解的那样,一直按住修饰键不放。 就这么一点点细微的差别,对了就通,不对就完全失效。 也让我第一次认真意识到,我们天天按的组合键背后其实有一套非常严谨的逻辑。 最后还有一个小麻烦,就是系统开启中文输入法的时候,会对 Unicode 的输入产生干扰,按键会被输入法拦截到选词框里,导致输出乱码。 而我们做的是非侵入式的硬件模拟,不能去修改对方电脑的设置,也不能安装任何软件,所以只能依靠硬件指令的方式提前清理状态,避开干扰,输入完成之后再恢复原状,全程不留下任何痕迹。 这也让我更加看明白一件事,中文输入法只是上层的一层包装,并不是底层输入必须遵守的规则。 真正稳定可靠的方式,反而是绕开这些上层工具,直接和系统底层对话。 整段经历走下来,其实技术难度并不算高,可给我的感触却特别深。 键盘和鼠标是每个人从第一次使用电脑就开始接触的东西,我们每天敲字点击,熟悉到不能再熟悉。 可真正理解底层逻辑的人其实并没有那么多。 有多少人知道按键是按下和释放两个事件?有多少人手动用过 Unicode 输入中文?有多少人想过没有输入法也能正常输出汉字?又有多少人真正理解组合键和输入法背后的原理?计算机发展到今天,界面越来越精致,功能越来越强大。 我们习惯了方便快捷的操作,却很少再去留意那些最基础、最底层、最朴素的东西。 这次踩坑让我最真实的感受就是,越平常越不起眼的东西,背后往往越不简单。 越是天天使用的基础功能,越值得我们静下心去看一眼它真正的样子。 很多时候不是事情本身有多难,而是我们太习惯想当然,忘了那些最根本的道理,其实一直都在最不起眼的地方。
英文翻译
The most seemingly ordinary keyboard and mouse actually hide underlying truths we all overlook. A real-world pitfall record of using CH340 plus CH9329 for hardware-based Chinese input. Recently, I played around with a set of CH340 plus CH9329 hardware keyboard-mouse simulation devices. I honestly thought it would be a trivial little task. Just plug it in, send a few commands, and make the system think someone is typing on the keyboard and clicking the mouse—easy, right? Especially something as everyday as typing Chinese—who would have thought it would hide so many pitfalls we normally never notice? But after actually running through the entire process from start to finish, I ended up with a lot of genuine feelings. I also suddenly realized that most people, including myself, who use the most familiar and ordinary keyboard and mouse every day, have never truly understood how they work at the bottom level. When I first started, I had a very presumptuous attitude—how complicated could such basic input devices be? But the very first piece of code I ran immediately failed. After clicking the mouse, it never released. After pressing a key on the keyboard, it stayed stuck. The whole interface went haywire, keys became unresponsive, and nothing could save it. Later, I finally understood one of the most basic yet easily overlooked things. When we press a mouse button or a key by hand, it looks like a single action. But in the underlying logic of the system and hardware, pressing and releasing are two completely independent events. Humans naturally release. But a machine simulation must complete both actions in full. Missing one will make the system think the key is being held down continuously, eventually causing a complete freeze. This small thing, though simple, thoroughly woke me up from my "just write some code and it will work" mindset. What really overturned my understanding was a detour I took regarding Chinese input. At first, like most people, I was led by long-term usage habits and naturally assumed that to input Chinese, you must have a Chinese input method installed—otherwise the system simply couldn't recognize Chinese characters. I even considered simulating Pinyin and simulating character selection, which would have been a completely roundabout approach. But as I dug deeper into the underlying layers, I discovered that I had been completely fooled by high-level usage habits. Modern operating systems have long supported Unicode natively. Any language, any character, is just a corresponding code at the system's bottom level. The system itself can directly recognize and display them—it has nothing to do with whether you have a Chinese input method installed. An input method is just a translation tool for human use, not a necessary condition for the system to run. This also made me suddenly realize that many things we take for granted as common sense are just habits formed by long-term use, not the actual underlying rules. Once I truly understood that Unicode can be used to input Chinese directly, I thought everything would go smoothly from then on. Isn't it just pressing a combination of Ctrl + Shift + U, typing the code, and pressing Enter? But in reality, I ran the code over and over, and the system just output a string of ordinary letters and numbers, never treating them as Chinese characters. Later, I found out that key combinations are not as casual as we imagine. A slight timing difference and the system won't recognize them at all. When I do it manually, I first hold down Ctrl + Shift, press U, see the underline appear, then immediately release the modifier keys and type the code normally. Finally, I press Enter to confirm. I would never keep holding down Ctrl + Shift while typing letters and numbers. The key to making the code work was precisely simulating this actual operational rhythm, not, as many misunderstand, holding down the modifier keys continuously. Such a tiny difference—if you get it right, it works; if not, it fails completely. This also made me realize for the first time seriously that behind the key combinations we use daily lies a very strict logic. Finally, there was one more small trouble: when the system has a Chinese input method enabled, it interferes with Unicode input. The keystrokes get intercepted by the input method into a candidate selection box, causing garbled output. And since we were doing non-invasive hardware simulation, we couldn't modify the other computer's settings or install any software. So we had to use hardware instructions to clear the state in advance, avoid interference, and restore everything after input—leaving no trace throughout. This also made me see more clearly: a Chinese input method is just a wrapper at the top layer, not a rule that must be followed for underlying input. The truly stable and reliable way is to bypass these high-level tools and communicate directly with the system's underlying layer. Looking back on the entire experience, the technical difficulty wasn't really high, but the insights it gave me were particularly deep. Keyboards and mice are the first things everyone touches when using a computer. We type and click every day—so familiar we couldn't be more familiar. But not that many people actually understand the underlying logic. How many people know that pressing a key involves two events: press and release? How many have manually used Unicode to input Chinese? How many have thought that you can output Chinese characters normally without an input method? How many truly understand the principles behind key combinations and input methods? As computers have developed to where they are today, interfaces have become more refined, and functions more powerful. We've grown accustomed to convenient and fast operations, but we rarely pay attention anymore to the most basic, most underlying, most unassuming things. This pitfall experience gave me the most genuine feeling: the more ordinary and insignificant something seems, the more complexity often lies beneath. The more we use a basic function every day, the more it deserves our calm attention to see what it truly is. Many times, it's not that something is inherently difficult—it's that we are too used to taking things for granted, forgetting that the most fundamental truths are always right there in the most inconspicuous places.
back to top