PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/misc/RemapJoystick.htm

http://autohotkey-chinese.googlecode.com/
HTML | 66 lines | 64 code | 2 blank | 0 comment | 0 complexity | 38df7201d014b9d43fc891532c443d57 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
  2. <HTML><HEAD><TITLE>Remapping a Joystick to Keyboard or Mouse</TITLE>
  3. <META http-equiv=Content-Type content="text/html; charset=UTF-8">
  4. <META
  5. content="Have your joystick send keystrokes and mouse clicks with this free macro program. It also allows a joystick to be used as a mouse."
  6. name=description>
  7. <META
  8. content=keyboard,keys,key,keystrokes,clicks,mouse,buttons,button,joystick,hotkeys,hotkey,macro
  9. name=keywords><LINK title="AutoHotkey Forum RSS" href="../../forum/rss.php"
  10. type=application/rss+xml rel=alternate><LINK href="../css/default.css"
  11. type=text/css rel=stylesheet><LINK media=print href="../css/print.css"
  12. type=text/css rel=stylesheet>
  13. <META content="MSHTML 6.00.6000.16735" name=GENERATOR></HEAD>
  14. <BODY>
  15. <H1>重映射游戏杆为键盘或鼠标</H1>
  16. <H2>目录</H2>
  17. <UL>
  18. <LI><A href="#imp">重要事项</A>
  19. <LI><A href="#button">让游戏杆按钮发送键击或者鼠标点击</A>
  20. <LI><A href="#axis">让游戏杆轴向(Joystick Axis)或者视点帽(POV Hat)发送键击或者鼠标点击</A>
  21. <LI><A href="#Remarks">备注</A> </LI></UL>
  22. <H2><A name=imp></A>重要事项</H2>
  23. <UL>
  24. <LI>虽然可以把游戏杆按钮或轴向重映射为按键或者鼠标按钮但是不能把它映射为另一个游戏杆按钮或轴向只能用游戏杆模拟器例如 <A
  25. href="http://www.geocities.com/deonvdw/Docs/PPJoyMain.htm">PPJoy</A> 来实现
  26. <LI>AutoHotkey 1 32 之间一个唯一的数字来定义游戏杆上的每个按钮要确定这些数字请用<A
  27. href="../scripts/JoystickTest.htm">游戏杆测试脚本</A> </LI></UL>
  28. <H2><A name=button></A>让游戏杆按钮发送键击或者鼠标点击</H2>
  29. <P>以下是三种由易到难的方式最复杂的方法适用于更广泛的情况例如需要将按键或者鼠标按钮按住不放的游戏</P>
  30. <P><STRONG>方法 #1</STRONG>: 此方法发送简单的键击和鼠标点击例如:</P><PRE>Joy1::<A href="../commands/Send.htm">Send</A> {Left} <SPAN class=CodeCom>;让按钮 #1 发送一个左箭头键击</SPAN><BR>Joy2::<A href="../commands/Click.htm">Click</A> <SPAN class=CodeCom>;让按钮 #2 发送一个鼠标左键点击</SPAN><BR>Joy3::Send a{Esc}{Space}{Enter} <SPAN class=CodeCom>;让按钮 #3 发送字母"a"后紧跟 Escape, Space Enter</SPAN><BR>Joy4::Send Sincerely,{Enter}John Smith <SPAN class=CodeCom>;让按钮 #4 发送一个两行的签名</SPAN></PRE>
  31. <P>要让一个按钮执行多个命令只要将第一个命令放在按钮名称<B>之下</B>并且使最后一个命令为 <A
  32. href="../commands/Return.htm">return</A>例如:</P><PRE>Joy5::<BR>Run Notepad<BR>WinWait 无标题 - 记事本<BR>WinActivate<BR>Send This is the text that will appear in Notepad.{Enter}<BR>return</PRE>
  33. <P>请看<A href="../KeyList.htm">按键列表</A>以获得完整的按键和鼠标/游戏杆按钮列表</P>
  34. <P><STRONG><BR>方法 #2</STRONG>:
  35. 此方法是在你按住一个游戏杆按钮的全程键盘按键或者鼠标按钮也必须一直按住的情况下才使用的下面的例子使游戏杆的第二个按钮成为左箭头按键</P><PRE>Joy2::<BR>Send {Left down} <SPAN class=CodeCom>;按住左箭头按键</SPAN><BR><A href="../commands/KeyWait.htm">KeyWait</A> Joy2 <SPAN class=CodeCom>;等待用户松开游戏杆按钮</SPAN><BR>Send {Left up} <SPAN class=CodeCom>;释放</SPAN><SPAN class=CodeCom>左箭头按</SPAN><SPAN class=CodeCom></SPAN><BR>return</PRE>
  36. <P><BR><STRONG>方法 #3</STRONG>: 此方法是你有多个在方法 #2
  37. 中所描述的游戏杆热键并且有时会同时按下或释放这些热键的情况下才使用下面的例子使游戏杆的第三个按钮成为鼠标左键</P><PRE>Joy3::<BR>Send {LButton down} <SPAN class=CodeCom>;按住鼠标左键</SPAN><BR>SetTimer, WaitForButtonUp3, 10<BR>return<BR><BR>WaitForButtonUp3:<BR>if <A href="../Functions.htm#GetKeyState">GetKeyState</A>("Joy3") <SPAN class=CodeCom>;按钮仍处于按下状态的话就继续等待</SPAN><BR>return<BR><SPAN class=CodeCom>;否则按键已松开</SPAN><BR>Send {LButton up} <SPAN class=CodeCom>;松开鼠标左键</SPAN><BR>SetTimer, WaitForButtonUp3, off<BR>return<BR></PRE>
  38. <P><STRONG><BR>自动重复某个键击</STRONG>有些程序或者游戏可能需要你重复地发送某个按键就像你在键盘上按着它不放下面的例子在你按住游戏杆的第二个按钮时通过重复地发送空格键键击来达到此目的</P><PRE>Joy2::<BR>Send {Space down} <SPAN class=CodeCom>;按下空格键</SPAN><BR>SetTimer, WaitForJoy2, <STRONG>30</STRONG> <SPAN class=CodeCom>;将数字 <STRONG>30 </STRONG>减为 20 10 可以更快地发送按键增加它会发送地更慢</SPAN><BR>return<BR><BR>WaitForJoy2:<BR>if not GetKeyState("Joy2") <SPAN class=CodeCom>;按钮已经释放</SPAN><BR>{<BR>Send {Space up} <SPAN class=CodeCom>;释放空格键</SPAN><BR>SetTimer, WaitForJoy2, off <SPAN class=CodeCom>;停止</SPAN><SPAN class=CodeCom>监视</SPAN><SPAN class=CodeCom>按钮</SPAN><BR>return<BR>}<BR><SPAN class=CodeCom>;因为上面没有return所以按钮依然处于按住状态</SPAN><BR>Send {Space down} <SPAN class=CodeCom>;发送另一个空格键键击</SPAN><BR>return</PRE>
  39. <P><STRONG>环境敏感的游戏杆按钮</STRONG><A
  40. href="../commands/_IfWinActive.htm">#IfWinActive/Exist</A>&nbsp;指令使选择的游戏杆按钮根据激活或存在的窗口类型而执行不同的动作(或者根本不执行)</P>
  41. <P><STRONG>把游戏杆当鼠标来用</STRONG><A
  42. href="../scripts/JoystickMouse.htm">Joystick-To-Mouse
  43. 脚本</A>通过重映射游戏杆的按钮和控制轴向把它变成鼠标</P>
  44. <H2><A name=axis></A>让游戏杆轴向或视点帽发送键击或者鼠标点击</H2>
  45. <P>要让脚本对游戏杆轴向或者视点帽的移动做出响应请用 <A href="../commands/SetTimer.htm">SetTimer</A>
  46. <A href="../commands/GetKeyState.htm">GetKeyState</A>下面的例子将使游戏杆的 X Y
  47. 轴表现得和键盘上的箭头按键群一样</P><PRE>#Persistent <SPAN class=CodeCom>;保持脚本运行直到用户明确地退出</SPAN><BR><A href="../commands/SetTimer.htm">SetTimer</A>, WatchAxis, 5<BR>return<BR><BR>WatchAxis:<BR><A href="../commands/GetKeyState.htm">GetKeyState</A>, JoyX, JoyX <SPAN class=CodeCom>;得到 x 轴的坐标</SPAN><BR>GetKeyState, JoyY, JoyY <SPAN class=CodeCom>;得到 y 轴的坐标</SPAN><BR>KeyToHoldDownPrev = %KeyToHoldDown% <SPAN class=CodeCom>; Prev 现在保存了先前按下的按键如果有的话<BR><BR></SPAN>if JoyX &gt; 70<BR> KeyToHoldDown = Right<BR>else if JoyX &lt; 30<BR> KeyToHoldDown = Left<BR>else if JoyY &gt; 70<BR> KeyToHoldDown = Down<BR>else if JoyY &lt; 30<BR> KeyToHoldDown = Up<BR>else<BR> KeyToHoldDown =<BR><BR>if KeyToHoldDown = %KeyToHoldDownPrev% <SPAN class=CodeCom>;已经按下了正确的按键或不需要按键</SPAN><BR> return <SPAN class=CodeCom>;什么也不做<BR><BR></SPAN><SPAN class=CodeCom>;否则松开先前的按键并按下一个新键</SPAN><BR>SetKeyDelay -1 <SPAN class=CodeCom>;避免击键之间的延时</SPAN><BR>if KeyToHoldDownPrev <SPAN class=CodeCom>;先前的按键需要松开</SPAN><BR> Send, {%KeyToHoldDownPrev% up} <SPAN class=CodeCom>;松开它</SPAN><BR>if KeyToHoldDown <SPAN class=CodeCom>;要按下一个键</SPAN><BR> Send, {%KeyToHoldDown% down} <SPAN class=CodeCom>;按下它</SPAN><BR>return</PRE>
  48. <P>&nbsp;</P>
  49. <P>下面的例子将让游戏杆的视点帽起到和键盘上的箭头按键群一样的作用就是说视点帽将发送方向键击</P><PRE>#Persistent <SPAN class=CodeCom>;</SPAN><SPAN class=CodeCom>保持脚本运行直到用户明确地退出</SPAN><SPAN class=CodeCom></SPAN><BR>SetTimer, WatchPOV, 5<BR>return<BR><BR>WatchPOV:<BR>GetKeyState, POV, JoyPOV <SPAN class=CodeCom>;获得视点</SPAN><SPAN class=CodeCom>控制</SPAN><SPAN class=CodeCom>的坐标</SPAN><BR>KeyToHoldDownPrev = %KeyToHoldDown% <SPAN class=CodeCom>; Prev 现在存储了先前按下的键如果有的话<BR><BR></SPAN><SPAN class=CodeCom>;有一些游戏杆会有平滑/连续的视角切换而不是固定的增幅&nbsp;</SPAN><BR><SPAN class=CodeCom>;要全部支持它们可用一个值域</SPAN><BR>if POV &lt; 0 <SPAN class=CodeCom>;没有角度</SPAN><BR> KeyToHoldDown =<BR>else if POV &gt; 31500 <SPAN class=CodeCom>; 315 360 向上</SPAN><BR> KeyToHoldDown = Up<BR>else if POV between 0 and 4500 <SPAN class=CodeCom>; 0 45 向上</SPAN><BR> KeyToHoldDown = Up<BR>else if POV between 4501 and 13500 <SPAN class=CodeCom>; 45 135 向右</SPAN><BR> KeyToHoldDown = Right<BR>else if POV between 13501 and 22500 <SPAN class=CodeCom>; 135 </SPAN><SPAN class=CodeCom></SPAN><SPAN class=CodeCom> 225 向下</SPAN><BR> KeyToHoldDown = Down<BR>else <SPAN class=CodeCom>; 225 315 向左</SPAN><BR> KeyToHoldDown = Left<BR><BR>if KeyToHoldDown = %KeyToHoldDownPrev% <SPAN class=CodeCom>;已经按下了正确的键或者不需要任何键</SPAN><BR> return <SPAN class=CodeCom>;什么也不做<BR><BR></SPAN><SPAN class=CodeCom>;否则释放先前的键并且按下一个新键:</SPAN><BR>SetKeyDelay -1 <SPAN class=CodeCom>;避免击键之间的延时</SPAN><BR>if KeyToHoldDownPrev <SPAN class=CodeCom>;先前的按键需要释放</SPAN><BR> Send, {%KeyToHoldDownPrev% up} <SPAN class=CodeCom>;释放它</SPAN><BR>if KeyToHoldDown <SPAN class=CodeCom>;需要按下一个键</SPAN><BR> Send, {%KeyToHoldDown% down} <SPAN class=CodeCom>;按下它</SPAN><BR>return</PRE>
  50. <P>&nbsp;</P>
  51. <P><STRONG>自动重复某个键击</STRONG>以上两个例子都可以修改为重复地发送按键而不仅仅是按住它也就是说它们可以模拟按住了键盘上的某键要做到这一点只需将下面这行</P><PRE>return <SPAN class=CodeCom>;什么也不做</SPAN></PRE>
  52. <P>替换为</P><PRE>{<BR> if KeyToHoldDown<BR> Send, {%KeyToHoldDown% down} <SPAN class=CodeCom>;自动地重复键击</SPAN><BR> return<BR>}</PRE>
  53. <H2><A name=Remarks></A>备注</H2>
  54. <P>也可以使用除了第一个之外的游戏杆只要通过在按钮或者轴名之前加上游戏杆编号例如2joy1 就是指二号杆的第一个按钮</P>
  55. <P>要获得更多有用的游戏杆脚本请访问 <A href="http://www.autohotkey.com/forum/">AutoHotkey
  56. 论坛</A>搜索关键词例如<EM> Joystick </EM><EM> GetKeyState </EM><EM> Send
  57. </EM>有可能找到你想要的主题</P>
  58. <H2>相关主题</H2>
  59. <P><A
  60. href="../scripts/JoystickMouse.htm">Joystick-To-Mouse&nbsp;脚本将游戏杆当鼠标用</A><BR><A
  61. href="../KeyList.htm#Joystick">游戏杆按钮轴向以及控制器的列表</A><BR><A
  62. href="../commands/GetKeyState.htm">GetKeyState</A><BR><A
  63. href="Remap.htm">重映射键盘和鼠标</A></P>
  64. </BODY></HTML>