/docs/misc/RemapJoystick.htm
HTML | 66 lines | 64 code | 2 blank | 0 comment | 0 complexity | 38df7201d014b9d43fc891532c443d57 MD5 | raw file
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
- <HTML><HEAD><TITLE>Remapping a Joystick to Keyboard or Mouse</TITLE>
- <META http-equiv=Content-Type content="text/html; charset=UTF-8">
- <META
- 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."
- name=description>
- <META
- content=keyboard,keys,key,keystrokes,clicks,mouse,buttons,button,joystick,hotkeys,hotkey,macro
- name=keywords><LINK title="AutoHotkey Forum RSS" href="../../forum/rss.php"
- type=application/rss+xml rel=alternate><LINK href="../css/default.css"
- type=text/css rel=stylesheet><LINK media=print href="../css/print.css"
- type=text/css rel=stylesheet>
- <META content="MSHTML 6.00.6000.16735" name=GENERATOR></HEAD>
- <BODY>
- <H1>重映射游戏杆为键盘或鼠标</H1>
-
-
- <H2>目录</H2>
- <UL>
- <LI><A href="#imp">重要事项</A>
- <LI><A href="#button">让游戏杆按钮发送键击或者鼠标点击</A>
- <LI><A href="#axis">让游戏杆轴向(Joystick Axis)或者视点帽(POV Hat)发送键击或者鼠标点击</A>
- <LI><A href="#Remarks">备注</A> </LI></UL>
- <H2><A name=imp></A>重要事项</H2>
- <UL>
- <LI>虽然可以把游戏杆按钮或轴向重映射为按键或者鼠标按钮,但是不能把它映射为另一个游戏杆按钮或轴向。只能用游戏杆模拟器例如 <A
- href="http://www.geocities.com/deonvdw/Docs/PPJoyMain.htm">PPJoy</A> 来实现。
- <LI>AutoHotkey 用 1 至 32 之间一个唯一的数字来定义游戏杆上的每个按钮。要确定这些数字,请用<A
- href="../scripts/JoystickTest.htm">游戏杆测试脚本</A>。 </LI></UL>
- <H2><A name=button></A>让游戏杆按钮发送键击或者鼠标点击</H2>
- <P>以下是三种由易到难的方式。最复杂的方法适用于更广泛的情况(例如需要将按键或者鼠标按钮按住不放的游戏)。</P>
- <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>
- <P>要让一个按钮执行多个命令,只要将第一个命令放在按钮名称<B>之下</B>并且使最后一个命令为 <A
- 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>
- <P>请看<A href="../KeyList.htm">按键列表</A>以获得完整的按键和鼠标/游戏杆按钮列表。</P>
- <P><STRONG><BR>方法 #2</STRONG>:
- 此方法是在你按住一个游戏杆按钮的全程,键盘按键或者鼠标按钮也必须一直按住的情况下才使用的。下面的例子使游戏杆的第二个按钮成为左箭头按键:</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>
- <P><BR><STRONG>方法 #3</STRONG>: 此方法是你有多个在方法 #2
- 中所描述的游戏杆热键,并且有时会同时按下或释放这些热键的情况下才使用。下面的例子使游戏杆的第三个按钮成为鼠标左键:</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>
- <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>
- <P><STRONG>环境敏感的游戏杆按钮</STRONG>:<A
- href="../commands/_IfWinActive.htm">#IfWinActive/Exist</A> 指令使选择的游戏杆按钮根据激活或存在的窗口类型而执行不同的动作(或者根本不执行)。</P>
- <P><STRONG>把游戏杆当鼠标来用</STRONG>:<A
- href="../scripts/JoystickMouse.htm">Joystick-To-Mouse
- 脚本</A>通过重映射游戏杆的按钮和控制轴向把它变成鼠标。</P>
- <H2><A name=axis></A>让游戏杆轴向或视点帽发送键击或者鼠标点击</H2>
- <P>要让脚本对游戏杆轴向或者视点帽的移动做出响应,请用 <A href="../commands/SetTimer.htm">SetTimer</A> 和
- <A href="../commands/GetKeyState.htm">GetKeyState</A>。下面的例子将使游戏杆的 X 和 Y
- 轴表现得和键盘上的箭头按键群(左、右、上、下)一样。</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 > 70<BR> KeyToHoldDown = Right<BR>else if JoyX < 30<BR> KeyToHoldDown = Left<BR>else if JoyY > 70<BR> KeyToHoldDown = Down<BR>else if JoyY < 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>
- <P> </P>
- <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>;有一些游戏杆会有平滑/连续的视角切换而不是固定的增幅。 </SPAN><BR><SPAN class=CodeCom>;要全部支持它们,可用一个值域:</SPAN><BR>if POV < 0 <SPAN class=CodeCom>;没有角度</SPAN><BR> KeyToHoldDown =<BR>else if POV > 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>
- <P> </P>
- <P><STRONG>自动重复某个键击</STRONG>:以上两个例子都可以修改为重复地发送按键,而不仅仅是按住它(也就是说,它们可以模拟按住了键盘上的某键)。要做到这一点,只需将下面这行:</P><PRE>return <SPAN class=CodeCom>;什么也不做。</SPAN></PRE>
- <P>替换为:</P><PRE>{<BR> if KeyToHoldDown<BR> Send, {%KeyToHoldDown% down} <SPAN class=CodeCom>;自动地重复键击。</SPAN><BR> return<BR>}</PRE>
- <H2><A name=Remarks></A>备注</H2>
- <P>也可以使用除了第一个之外的游戏杆,只要通过在按钮或者轴名之前加上游戏杆编号。例如,2joy1 就是指二号杆的第一个按钮。</P>
- <P>要获得更多有用的游戏杆脚本,请访问 <A href="http://www.autohotkey.com/forum/">AutoHotkey
- 论坛</A>。搜索关键词例如<EM> Joystick </EM>和<EM> GetKeyState </EM>和<EM> Send
- </EM>有可能找到你想要的主题。</P>
- <H2>相关主题</H2>
- <P><A
- href="../scripts/JoystickMouse.htm">Joystick-To-Mouse 脚本(将游戏杆当鼠标用)</A><BR><A
- href="../KeyList.htm#Joystick">游戏杆按钮、轴向以及控制器的列表</A><BR><A
- href="../commands/GetKeyState.htm">GetKeyState</A><BR><A
- href="Remap.htm">重映射键盘和鼠标</A></P>
- </BODY></HTML>