[Question] I'm trying to manipulate keystrokes in Go using evdev, uinput, and syscall and I've hit a snag. Any assistance would be appreciated.

xuanbao · · 592 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello everyone!</p> <p>To start: I&#39;m relatively new to Go and compiled languages in general. The overwhelming majority of my dev experience is with PHP and Python. That said, I spent several hours the other night trying to make my laptop keyboard act like my desktop keyboard. It&#39;s called a Poker 3 and it&#39;s a minimal 61 key layout that maps all the extra keys using an extra function key, and it has a switch to turn the caps lock key into the extra function key as well. Turns out there is absolutely no reasonable way to emulate this in Linux with existing software, so here we are.</p> <p>Anyway, I&#39;ve been able to get a solid proof-of-concept working in Python with only one major snag and this is largely to do with the rather well put together and well documented python-evdev library. While I was half brain-dead from lack of sleep dealing with said snag I thought I&#39;d take on my first reasonably practical Go project.</p> <p>Here&#39;s the Python proof-of-concept: <a href="https://gist.github.com/kendalltristan/aa873137751e3f11a9102e1174ec0d61" rel="nofollow">https://gist.github.com/kendalltristan/aa873137751e3f11a9102e1174ec0d61</a></p> <p>Here&#39;s the Go implementation thus far: <a href="https://gist.github.com/kendalltristan/9fcd9c4b700b22cafc7789cfca4e8a2c" rel="nofollow">https://gist.github.com/kendalltristan/9fcd9c4b700b22cafc7789cfca4e8a2c</a></p> <p>To the specifics, the issue I&#39;m having is with syscall calling ioctl. Essentially in order to accomplish what I need to accomplish, input from non-specified keys needs to be prevented while holding down the caps lock key. The function in question begins on line 23 and is called from lines 100 and 106. Go&#39;s syscall library doesn&#39;t have a function for ioctl so I had to steal one from somewhere. Anyway, that part <em>seems</em> to work; the larger issue is that once I &#34;grab&#34; the input device, I can&#39;t seem to &#34;ungrab&#34; it (look at the Python implementation to get what I mean). Basically pressing the caps lock key now effectively shuts off the keyboard while the program is running.</p> <p>Now some input absolutely should be prevented so I&#39;m reasonably certain I&#39;m pointed in the right direction. Now I&#39;m in the position of not knowing either enough Go or enough of how input interacts with the kernel to progress any farther. If anyone can offer assistance, I&#39;d greatly appreciate it and I&#39;ll be happy to buy gold for anyone who can provide or point me to a solution. Thanks in advance for your time and assistance. Cheers.</p> <hr/>**评论:**<br/><br/>TheMerovius: <pre><blockquote> <p>It&#39;s called a Poker 3 and it&#39;s a minimal 61 key layout that maps all the extra keys using an extra function key, and it has a switch to turn the caps lock key into the extra function key as well. Turns out there is absolutely no reasonable way to emulate this in Linux with existing software, so here we are.</p> </blockquote> <p>Really? All of that sounds very similar to what the <a href="http://neo-layout.org/" rel="nofollow">neo-layout</a> does and that works with straight xkb/xmodmap. It has 6 layers, accessed through combinations of 3 modifiers and relies both on reusing capslock as a modifier <em>and</em> remapping two keys that aren&#39;t normally modifiers to be modifiers.</p> <p>I can&#39;t really help you with your actual problem, but maybe looking at what neo does can help you achieve the same thing with stock linux software?</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

592 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传