Help Me Grow the Go userbase

Hello Everyone,

Lynda.com has hired me to do the “code clinic” using Go.

I’ve nailed 4 of the 5 challenges, but this one is stumping me.

Do you have any ideas on how to capture mouse X,Y position?

The lynda.com “code clinic” includes a challenge to have your mouse control sound, and I’d like to figure out how best to do it, eg, easiest, most explainable, most appealing, showcases Go.

Here are the specs of the challenge:
– mouse click means on
– up/down = increase / decrease volume
– left/right = decrease / increase pitch

Thank you for your help brainstorming on this!

This will be entirely driven by the OS you need to do it on, and you’ll need to do it using the OS API. Which OS is this for?

If anything this is also not a ‘great’ fit for Go—talking with the (e.g.) Win32 API isn’t a great example of Go as a language.

Hi Matt,

Yes, I was thinking the OS package, also.

I was wondering if there was some way to switch the Stdin to the mouse instead of the keyboard.

I will be creating this for
Mac OS X
10.10.5

Thank you for any suggestions you can provide!

Probably the most straightforward answer is to leverage work that has been done in C. Look at SDL2 and therefore the go bindings https://github.com/veandco/go-sdl2. It looks like there exist examples for everything you need to do.

Thank you. I’m looking into this!

Thank you, Mark. I just ran some of the examples and captured mouse X,Y in an open window, and another one which produced sound.

I wish there was some way to do this natively in Go without binding to C.

I want to showcase Go, not some binding.

Any other thoughts?

I was thinking about https://godoc.org/syscall#pkg-constants which has a lot of constants which I don’t understand. I saw a cool program using that in Ivo Balbaert’s book:

https://github.com/nsf/termbox-go will allow you to write a terminal application in Go that can use the mouse (no sound though).

If you want to create a GUI application you will definitely need to use some kind of C-bindings because there doesn’t exist (to my knowledge) a bridge between Go and OS X’s windowing server.

Creating a GUI app isn’t one of Go’s strong points right now, and GUI bindings in most languages are a bit of work to get going.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.