PC keyboard support?

Hi, I’m new to repository things. Do I only need to redownload all the files from github and replace the old ones to make it work?

Thanks.

Hey everyone,

I’ve got an existing Cocos2D-X project set up, and I’d love to add keyboard support to it. Does anyone have a list of the files I should modify?

lino lino wrote:

Hi, I’m new to repository things. Do I only need to redownload all the files from github and replace the old ones to make it work?
>
Thanks.

I have this question as well. Can someone please answer this? Thanks.

The easiest solution would be to use develop branch of cocos2dx (https://github.com/cocos2d/cocos2d-x/tree/develop). There is a big change that you won’t encounter any problems. And after first stable release which would contain all of the necessary changes you can switch to that stable version.

But if you insist on overwriting just files where is keyboard implemented then you can get list of files from two of my pull requests:


But there is a big chance that this won’t work because in these files where lot of different changes afterwards but you can look at the changes, understand them and make them in files in the stable version.

Also in my original implementation there was necessary to define directives CC_KEYBOARD_SUPPORT or KEYBOARD_SUPPORT.
In the latest version these macros are not necessary and everything should work without them.

Then I just have to download the develop branch and replace my cocos2d-x folder with it, and then copy my projects into it? Thanks again.

You will propably have to edit your project a little. For example they renamed lot of “CCClasses” into their version without CC, for example CCSize > Size, CCRect> Rect, CCPoint -> Point etc. Also when you are using some kind of cocos callbacks then you will have to change them into their std::bind/std::fuction equivalent because as cocos2dx started using C++11 they have refactored lot of code.

Also, when moved from 2.1.4 to develop, I get a lot of LNK errors. Any clue of how to solve that?

Alejandro Alarcon wrote:

Also, when moved from 2.1.4 to develop, I get a lot of LNK errors. Any clue of how to solve that?

Try to delete all already compiled objects and try to compile the project from scratch.

René Klačan wrote:

Try to delete all already compiled objects and try to compile the project from scratch.

It keeps the same, and now it also says pthreadVCE2.lib is missing.

Alejandro Alarcon wrote:

It keeps the same, and now it also says pthreadVCE2.lib is missing.

Don’t use original project files but download clean source code and then open its project file and there you go. After successful compilation of cocos2dx you can link it to your project.

René Klačan wrote:

Don’t use original project files but download clean source code and then open its project file and there you go. After successful compilation of cocos2dx you can link it to your project.

OK, I created a new project and copied the code from the old one. Thank you so much.

Hi, I’m having some issue with keybord on win32.
Everytime I press a button and hold it, the

void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);

method is called every 1/30 of second with every framerate I set. It’s not how it is supposed to behave isn’t it?
I’m using the latest develop branch from github.

i have the same problem with @KarolStola, when i hold it, it calls onRelease function.

I got the same problem here… After holding any key for a little while, onRelease gets called repeatedly until releasing the key. As logged:

Key 100 pressed!
Key 100 released!
Key 100 released!
Key 100 released!
Key 100 released!

I’m using the latest 3.0 release, cocos2d-x-3.0alpha0.

While looking at commits in repo, I’ve found this:
https://github.com/cocos2d/cocos2d-x/commit/378ff345fa69e25a4091c72b7e151e1c3942b1ee
I’ll try to put it into my version later today and check if it works.

Affirmative, it works for multipile release calls.

thankyou so much, i have no idea about GLFW. U make my day :slight_smile:

https://github.com/cocos2d/cocos2d-x/commit/378ff345fa69e25a4091c72b7e151e1c3942b1ee

It is now pulled into the develop branch :slight_smile:

René Klačan wrote:

So I have implemented keyboard support throught glfw

Hmm… I can’t find this implementation throught glfw. Where is it?
I found the implementation throught WinApi, but it’s not perfect because it seems WindowProc and thus keyboard dispatcher are not called every frame. This prevents using this solution for character control, since character’s movement becomes jerky.
Can’t switch to v3.0 either.
Any help?

UPD: oh, I see, glfw is used in Linux version.

Just to verify, the Cocos2D-x 3.0 has the support, but there will be no “official” support for the ones before?

Someone has had any hard time adapting the code of the 3.0 to the 2.2.1?

Thanks!