Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

WiiHotkey - Wiimote Wii remote controller + ahk


  • Please log in to reply
7 replies to this topic
hyz1984
  • Members
  • 22 posts
  • Last active: Mar 28 2010 07:56 PM
  • Joined: 12 Nov 2008
Hi! This would be my first contribution to AutoHotkey Community.

The idea is simple, to use Wiimote + AutoHotkey to do anything.

I just spent a few hours implemented this idea simply to control KMPlayer (a media player) with Wiimote through Bluetooth connection. For now only the buttons on Wiimote is used. It's better than inferred R/C since you don't have to point your controller to the receiver. Also with integrated sensors in Wiimote, you might be able to do a lot more things than inferred, but I haven't implemented those yet.

Any comments/suggestions/help/improvements are appreciated !!!
David H.

hyz1984
  • Members
  • 22 posts
  • Last active: Mar 28 2010 07:56 PM
  • Joined: 12 Nov 2008
How it is done:

I created an application called WiiHotkey.exe than reads the info from Wiimote and send messages to an ahk script, WiiHotkey.ahk, which then do things using the powerful ahk commands.

I used a free C++ Wiimote library WiiYourself! http://wiiyourself.gl.tter.org/ and [module] IPC 1.0 http://www.autohotke...topic21699.html
Sincerely thank the authors of WiiYourself! and IPC 1.0 for making this possible!
I'm not smart enough to figure out how to use dll calls for some Wii libraries, and I don't know how to make dlls integrate with AutoHotkey, so my implementation may be silly but it works.

How to use it:

1. You need to enable/activate your bluetooth connection in windows OS, add new bluetooth devices to connect your Wiimote to your computer .

Note: When searching for new device, hold down both "one" and "two" buttons on Wiimote, it should be detected. When prompt for code, click "pass", since Wiimote doesn't need any code for connection. It should work with most bluetooth adaptors and drivers, in fact I believe WiiYourself is the most compatiable Wii driver for Windows OS.

2. run WiiHotkey.exe and WiiHotkey.ahk. Modify the ahk according to your own needs. When buttons are pressed on the Wiimote, corresponding messages are sent to WiiHotkey.ahk. Possible buttons are:
A, up, down, left, right, minus, plus and home. Also if you press these buttons while holding down B, it sends different messages, see the comments in ahk script. To quit the exe application, press home button.

Almost forgot, if you run "WiiHotkey.exe beep" then your main-board will beep when buttons are pressed (implemented in C++ and beep doesn't work with laptops, but you can change the ahk script to have Autohotkey beep or play sound files)

For the posted WiiHotkey.ahk, you can do the following with KMPlayer:
up/down: system volume
left/right: fastforward/rewind 30 seconds
minus/plus: max/min/restore player window
one: toggle aspect ratio
B+up/down: previous/next video
B+left/right: fastforward/rewind 5 seconds
(some buttons may not work as above, check your KMPlayer for hotkey settings.)


The link for the application WiiHotkey.exe (release version). Thanks to rapidshare. BTW, how do I upload files in this forum? I'm a newbie :)

<!-- m -->http://rapidshare.co...8/WiiHotkey.exe<!-- m -->
========== UPDATE ================
solution files including the executeable WiiHotkey.exe and the srcipt WiiHotkey.ahk can be downloaded from here

<!-- m -->https://ahknet.autoh...4/WiiHotkey.rar<!-- m -->

You don't need to download extra libraries for it, all the header and *.lib files are included. Just extract and compile in Visual Studio 2008. If you don't have VS2008 and you don't intend to modify the code, then just use the complied executeable WiiHotkey.exe.

MD5 for WiiHotkey.exe: 3CE0C114BCC5B72349C218CDED2745A2
Tested on Win XP sp2/3.
You also need Microsoft Visual C++ 2008 Redistributable Package (x86), which can be downloaded in the following link, or just search for "vcredist_x86.exe".
<!-- m -->http://www.microsoft... ... laylang=en<!-- m -->



here's the WiiHotkey.ahk code:
#SingleInstance, on	;do not allow multiple instances

	Program_Name = KMPlayer.exe
	win_min = 0

	Gui, +LastFound	  +AlwaysOnTop
	hScript := WinExist()

	Gui, Add, ListView, r1 w90 gMyListView , msg|btn

	Gui, Add, Button, x10 y40 w90 h30 , Exit

	Gui, Show,	x200 AutoSize

	IPC_OnMessage("OnMessage")
return

OnMessage:

	StringLeft, IPC_Message, IPC_Message, 1

; btn[] 0 1  2    3        4   5    6  7  8           9      10
; btn[] A B Up Down  <-  ->   -   +  Home  One   Two
; msg 0     2    3        4   5    6  7               9      t
; msg a     b    c        d   e     f  g               h      i   ( with B pressed )

DetectHiddenWindows, On 
WinActivate   ahk_class Winamp v1.x

if ( IPC_Message = "0") ; A
{
BTN_Pressed = A
Send {Space}
}

else if ( IPC_Message = "2") ; Up
{
BTN_Pressed = Up
SoundSet +1
Gosub ShowSoundVolume
}

else if ( IPC_Message = "3") ; Down
{
BTN_Pressed = Down
SoundSet -2
Gosub ShowSoundVolume
}

else if ( IPC_Message = "4") ; Left
{
BTN_Pressed = Left
Send {Left}
}

else if ( IPC_Message = "5") ; Right
{
BTN_Pressed = Right
Send {Right}
}

else if ( IPC_Message = "6") ; Minus
{
BTN_Pressed = Minus
	if ( win_min = 1 )
	{
	WinRestore ahk_class Winamp v1.x
	win_min = 0
	}
	else
	{
	WinMinimize ahk_class Winamp v1.x
	win_min = 1
	}
}


else if ( IPC_Message = "7") ; Plus
{
BTN_Pressed = Plus
Send {Alt Down}{Enter}{Alt Up}
}


else if ( IPC_Message = "9") ; One
{
BTN_Pressed = One
SendPlay {Alt Down}{SC029}{Alt Up}
}


else if ( IPC_Message = "t") ; Two
{
BTN_Pressed = Two
}





else if ( IPC_Message = "a") ; B+A
{
BTN_Pressed = B+A
}

else if ( IPC_Message = "b") ; B+Up
{
BTN_Pressed = B+Up
Send {PgUp}
}


else if ( IPC_Message = "c") ; B+Down
{
BTN_Pressed = B+Down
Send {PgDn}
}


else if ( IPC_Message = "d") ; B+Left
{
BTN_Pressed = B+Left
Send {Ctrl Down}{Left}{Ctrl Up}
}


else if ( IPC_Message = "e") ; B+Right
{
BTN_Pressed = B+Right
Send {Ctrl Down}{Right}{Ctrl Up}
}


else if ( IPC_Message = "f") ; B+Minus
{
BTN_Pressed = B+Minus
}


else if ( IPC_Message = "g") ; B+Plus
{
BTN_Pressed = B+Plus
}


else if ( IPC_Message = "h") ; B+One
{
BTN_Pressed = B+One
}


else if ( IPC_Message = "i") ; B+Two
{
BTN_Pressed = B+Two
}

LV_Delete()
LV_Add("", IPC_Message, BTN_Pressed)
GuiControl, -Redraw, ListView

return

MyListView:

if A_GuiEvent = DoubleClick
{
ExitApp
 }
return


ShowSoundVolume:
SoundGet, master_volume
master_volume *= 100
master_volume := master_volume // 100
StringGetPos, pos, master_volume, .
StringLeft, OutputVar, master_volume, pos
TrayTip, , %OutputVar%`%
SetTimer, RemoveTrayTip, -1200
return

RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return

ButtonExit:
ExitApp
return

GuiClose:
ExitApp
return

;Title:		IPC
;			Inter Process Communication using WM_COPYDATA
;

;-------------------------------------------------------------------------
; Function:	 Send
;			 Send the message to another process (receiver) using WM_COPYDATA.
;
; Parameters:
;			 hwnd - Handle of the receiver
;			 msg  - Optional message to be sent. Default is empty message.
;			 port - Optional port, by default 100
;
; Returns:	 
;			 FAIL on error, 0 on success
;
IPC_Send(hwnd, msg="", port=100) {
	static WM_COPYDATA = 74, id=951753	;id is for security reasons

	len := StrLen(msg)              
	VarSetCapacity(CopyDataStruct, 12, 0)
	NumPut(port,	CopyDataStruct, 0)
	NumPut(len + 1, CopyDataStruct, 4)             
	NumPut(&msg,	CopyDataStruct, 8)             
	
   	SendMessage, WM_COPYDATA, id, &CopyDataStruct,, ahk_id %hwnd%
	return ErrorLevel
}

;-------------------------------------------------------------------------
; Function:	 OnMessage
;			 Set the message handler
;
; Parameters:
;			 label - Subroutine that will be called when message is received.
;					 IPC_Message & IPC_Port global vars will contain message info.
;
; Returns:	 
;			 false invalid label, true on success
;
IPC_OnMessage( pLabel ){
	global
	static WM_COPYDATA = 74, id=951753	;id is for security reasons

	if !IsLabel(pLabel)
		return false
	
	IPC_OnMessage := pLabel
	OnMessage(WM_COPYDATA, "IPC_OnCopyData")
	return true
}

;private IPC function, wm_copydata monitor
IPC_OnCopyData(wparam, lparam) {
	local  pStr

	IPC_Port := NumGet(lparam+0), pStr	 := NumGet(lparam+8)
	IPC_Message := DllCall("MulDiv", "Int", pStr, "Int",1, "Int",1, "str") 

	gosub %IPC_OnMessage%
	return 1
}

;-------------------------------------------------------------------------------
;Group:	About
;		- Version 1.0 by majkinetor <http://code.r-moth.com>.
;		- Licenced under GNU GPL <http://creativecommons.org/licenses/GPL/2.0/>.

Known issues:
1. The messages being sent weren't supposed to have only one character, but something like "home", "down", etc. Somehow ahk only receives (or my application only sends) the first character. I don't know what's wrong with my code, I had it working for a while. Maybe something to do with ATL class?
2. The application uses a simple while loop to send messages according to buttons pressed on Wiimote, with interval of 120 milli-seconds. This could be improved by detecting button-pressed and button-released.
David H.

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
Looks interesting... Where can IPC.ahk be found?

hyz1984
  • Members
  • 22 posts
  • Last active: Mar 28 2010 07:56 PM
  • Joined: 12 Nov 2008

Looks interesting... Where can IPC.ahk be found?

Thanks for your interest! I updated my post to include more things, including IPC.ahk script.
David H.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
Hi, this looks really cool! But the rapidshare link is broken for me. May I suggest using our ftp site? It only costs $250/mo! LOL jk jk it's free and perfect for ahk stuff. ;)

Link: https://ahknet.autohotkey.com
About: http://www.autohotke...pic.php?t=36756

:D

hyz1984
  • Members
  • 22 posts
  • Last active: Mar 28 2010 07:56 PM
  • Joined: 12 Nov 2008
I totally forgot about this :(

Thanks for the tip, solution files including the executeable WiiHotkey.exe and the srcipt WiiHotkey.ahk can be downloaded from here:

<!-- m -->https://ahknet.autoh...4/WiiHotkey.rar<!-- m -->

You don't need to download extra libraries for it, all the header and *.lib files are included. Just extract and compile in Visual Studio 2008. If you don't have VS2008 and you don't intend to modify the code, then just use the complied executeable WiiHotkey.exe.



Hope this link won't expire :) ENJOY :)
David H.

unknown tipper
  • Guests
  • Last active:
  • Joined: --
well heres the thing , i just downloaded BOTH the rapidshare .exe file , and the ahk.net .rar file , both of the .exe files acted like a incomplete download , BUT if the .rar file wasnt complete it would not have unziped at all , and as that is the only thing i had downloaded and ran before it happened , i am lead to belive that THIS IS A VIRUS

what happened to me was it killed my sound driver , idk what else it was ment to do but i cleaned it out rather quickly .

angelshurikan
  • Members
  • 1 posts
  • Last active: Jul 11 2013 04:57 PM
  • Joined: 11 Jul 2013

Hello I wanted to know where can I find the file wiihotkey.exe