Jump to content


Photo

Extra Key Remaps for Minecraft


  • Please log in to reply
10 replies to this topic

#1 Desi

Desi
  • Members
  • 161 posts

Posted 29 October 2010 - 05:34 AM

This script creates extra keybinds for use in the ridiculously fun indie game Minecraft. After a few hours of playing your fingers and hands begin to go a little numb because you're basically just holding Left-Click down endlessly, and sometimes you’d let go of the Crouch key just for a second, and then fall off your building-in-progress.

Download page with more information is at http://www.desiquint...minecraftremaps, source code is below.

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

#IfWinActive, Minecraft
{
	XButton1::LButton ; Remaps button 4 to left-click

	; The following autopilot code was borrowed from jaceguay at http://www.autohotkey.com/forum/topic59506.html
	F1::Send % "{LButton " ((Cnt := !Cnt) ? "Down}" : "Up}" )

	;The following crouch-toggle code was borrowed from Lanser at http://www.autohotkey.com/forum/topic16058.html
	~LCtrl up::
	  Goto, Crouch
	
	Crouch:
	  If (a_tickCount-lasttime < 400)
	  {
	    Loop
	    {
	      Send, {LCtrl down}
	      If IsKeyPressed("LCtrl")
	        Send, {LCtrl up}
	      Break
	    }
	  }
	  lasttime:=a_tickCount
	Return
	
	IsKeyPressed(v_KeyName)
	  {
	    GetKeyState, state, %v_KeyName%, P
	    If state = D
	    {
	      Return 1
	    }
	    Return 0
	  }
}

PrintScreen::^F11 ;Remaps Ctrl+F11 to PrintScreen for easy screenies via IrfanView.


#2 sumon

sumon
  • Moderators
  • 1307 posts

Posted 29 October 2010 - 12:10 PM

Sweet! I was just waiting for the first Minecraft script to pop up.

However, does it have anything like autowalk? Cos that's what I wanted the most... sooo, I made a script for it. Shift+Scroll up = Autowalk+Automine (so useful for mining straight tunnels, just line it up and relax your fingers for a bit), and shift+scrolldown = Stop autowalk.

~LShift & WheelUp::  
Gosub, Autowalk
return
~LShift & WheelDown::  
Gosub, AutowalkSTOP
return

Autowalk:
Click, Down
Send, {w down}
return
AutoWalkStop:
Click, Up
Send, {w up}
Return


#3 Desi

Desi
  • Members
  • 161 posts

Posted 03 November 2010 - 08:45 PM

However, does it have anything like autowalk?

Your question was an excellent one, so I made an auto-walk toggle too. v2 has auto-walk, as well as a fix for pressing PrintScreen when IrfanView isn't running (which would make Minecraft fullscreen and potentially mess up the pointer).

Download the package from http://www.desiquint...minecraftremaps, or snag the new code below.

;
; Minecraft Remaps v2
; Author:			Desi Quintans <me@desiquintans.com>
; Website:			http://www.desiquintans.com
;
; Script Function:
;  The following only apply inside the Minecraft window:
;	1) Mouse Button 4 performs a left-click.
;	2) F1 toggles hold-left-click. Handy for breaking lots of blocks or mining obsidian.
;	3) F2 toggles hold-W, making you move forward automatically. Use with F1 for automated mining action!
;	4) LCtrl toggles crouching upon double-pressing it. Press it again (once) to turn off.
;  The following only applies if IrfanView is running.
;	5) PrintScreen -> Ctrl+F11 for taking screenies via IrfanView.
;

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

#IfWinActive, Minecraft
{
	XButton1::LButton ; Remaps button 4 to left-click

	; The following autopilot code was borrowed from jaceguay at http://www.autohotkey.com/forum/topic59506.html
	F1::Send % "{LButton " ((Cnt := !Cnt) ? "Down}" : "Up}" )
	F2::Send % "{w " ((Cnt2 := !Cnt2) ? "Down}" : "Up}" )

	;The following crouch-toggle code was borrowed from Lanser at http://www.autohotkey.com/forum/topic16058.html
	~LCtrl up::
	  Goto, Crouch
	
	Crouch:
	  If (a_tickCount-lasttime < 400)
	  {
	    Loop
	    {
	      Send, {LCtrl down}
	      If IsKeyPressed("LCtrl")
	        Send, {LCtrl up}
	      Break
	    }
	  }
	  lasttime:=a_tickCount
	Return
	
	IsKeyPressed(v_KeyName)
	  {
	    GetKeyState, state, %v_KeyName%, P
	    If state = D
	    {
	      Return 1
	    }
	    Return 0
	  }
}

#IfWinExist, IrfanView
{
	PrintScreen::^F11 ;Remaps Ctrl+F11 to PrintScreen for easy screenies via IrfanView.
}


#4 nimda

nimda
  • Members
  • 4301 posts

Posted 18 March 2011 - 07:38 PM

See here for my criticism ;)

#5 Desi

Desi
  • Members
  • 161 posts

Posted 18 March 2011 - 09:05 PM

The ISKeyPressed function you're talking about is indeed wasteful, but it isn't my code. I grabbed it from someplace else when I was a noob at Autohotkey.

#6 nimda

nimda
  • Members
  • 4301 posts

Posted 18 March 2011 - 09:56 PM

...and the loop?

#7 Desi

Desi
  • Members
  • 161 posts

Posted 19 March 2011 - 02:34 AM

Yes, the function and the loop are all from someone else's code. If you feel so strongly about it, you should take it up with the original author, whose name and original post I clearly credited above the code block, at the start of the script, in the readme, and on the download page at my site.

;The following crouch-toggle code was borrowed from Lanser at http://www.autohotkey.com/forum/topic16058.html

Your next question may be, "If you know better now, why don't you fix the code?" The answer is that it is not worth spending 2-5 minutes to rewrite very old code that is completely functional, with only a negligible performance hit.

#8 nimda

nimda
  • Members
  • 4301 posts

Posted 19 March 2011 - 05:38 PM

I have taken it up with the original author now. I had followed this code through several layers (in a ask for help thread which linked to another one which linked here...) so that is why I missed those credits. Plus I wasn't looking for it, because code like that (<20 lines) shouldn't have a page of credits at the top, so I skipped right over all of the green

#9 krazykylep

krazykylep
  • Guests

Posted 31 March 2012 - 08:19 PM

Not related to WorldEdit however...
I am sick of double tapping w to sprint. So I made this autohotkey script.
Shift + w to sprint. Hope this helps someone.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

#IfWinActive, Minecraft
MYFLAG=0
SHIFTDOWN=0
WDOWN=0

Shift::
SHIFTDOWN := 1
If(WDOWN = 1 && MYFLAG = 0){
    MYFLAG := 1
    Send {w Up}
    Sleep 80
    Send {w Down}
    Sleep 80
    Send {w Up}
    Sleep 80
    Send {w Down}
}
return

Shift Up::
MYFLAG := 0
SHIFTDOWN := 0
Sleep 80
Send {w Up}
If(WDOWN = 1){
    Sleep 50
    Send {w Down}
}
return

w::
WDOWN := 1
Send {w Down}
If(MYFLAG = 0 && SHIFTDOWN = 1){
    MYFLAG := 1
    Send {w Up}
    Sleep 80
    Send {w Down}
    Sleep 80
    Send {w Up}
    Sleep 80
    Send {w Down}
}
return

w Up::
WDOWN := 0
MYFLAG := 0
Send {w Up}
return

I am no autohotkey pro: sorry if this is a bad or roundabout way of doing it... but it works.

#10 krazykylep

krazykylep
  • Guests

Posted 31 March 2012 - 09:04 PM

oh i forgot something important.... I forgot to send shift up and down in the shift hotkeys. If you dont do this, then you cant shift click things in and out of chests.

Shift::
SHIFTDOWN := 1
Send {Shift Down}
If(WDOWN = 1 && MYFLAG = 0){
	MYFLAG := 1
	Send {w Up}
	Sleep 80
	Send {w Down}
	Sleep 80
	Send {w Up}
	Sleep 80
	Send {w Down}
}
return

Shift Up::
Send {Shift Up}
MYFLAG := 0
SHIFTDOWN := 0
Sleep 80
Send {w Up}
If(WDOWN = 1){
	Sleep 50
	Send {w Down}
}
return


#11 Barrow

Barrow
  • Members
  • 30 posts

Posted 01 April 2012 - 03:47 PM

Nice script krazykylep, this is so much nicer than relying on the old double-tap. I hope you don't mind, but I took the liberty of cleaning it up a little bit:

#NoEnv
SetKeyDelay, 80	; Adjust as needed
Sprinting := FALSE
Return
#IfWinActive, Minecraft

~*w::
	If(GetKeyState("Shift","P") && !Sprinting)
		Sprint()
return

~Shift::
	if(GetKeyState("w","P") && !Sprinting)
		Sprint()
return

~w Up::
~Shift Up::
	If(Sprinting)
	{
		If(GetKeyState("w","P"))
		{
			Send {w Up}{w Down}
		}
		Sprinting := FALSE
	}
return

Sprint()
{
	Global Sprinting := TRUE
	Send {w Up}{w Down}{w Up}{w Down}
	Return
}