Wchris Posted March 5, 2010 Share Posted March 5, 2010 Hello, First, i don't want to use keyhit/keydown because the command requires me to know what key will be pressed. I don't want to specify what key was pressed. Instead i want to use GETCHAR to get the keycode that was pressed and launch an event. Some kind of callback that would launch if any key was pressed, and then tell me what key it was. but if i say : key = GetChar(); if (key==KEY_A) { DoSomething(); } it works and if i say : key = GetChar(); if (key==KEY_UP) { DoSomething(); } it doesn't i can't get GETCHAR to work with special keys. A i doing something wrong ? i saw masterxilo using hooks and callbacks in the old forum to achieve this http://forum.leadwerks.com/viewtopic.php?f=2&t=3236&p=28267&hilit=hook#p28267 but his solution is not cross platform, so i would prefer a pure LE GETCHAR solution. Any idea ? Thank you Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
Rick Posted March 5, 2010 Share Posted March 5, 2010 I seem to remember that GetChar() only returned printable keys. Why don't you want to have to know what key is pressed? I can understand if you are printing the key to screen or something but KEY_UP can't be printed to screen so you would need to check for it anyway, so then why not use KeyHit()/KeyDown()? Quote Link to comment Share on other sites More sharing options...
Wchris Posted March 5, 2010 Author Share Posted March 5, 2010 I seem to remember that GetChar() only returned printable keys. Why don't you want to have to know what key is pressed? I can understand if you are printing the key to screen or something but KEY_UP can't be printed to screen so you would need to check for it anyway, so then why not use KeyHit()/KeyDown()? well is ask here in the c++ forum because the pascal forum is empty so i have more change to get an answer here. But in fact i'm trying to create a delphi component for LE. Components are 'event driven objects' like in the screenshot so you see the keydown event launches the Formkeydown method where you get the key. So if i want to write my own component i have to be able to send the key that was pressed to the event method. understood ? Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted March 5, 2010 Share Posted March 5, 2010 I would use a function to pull the key ascii codes not the character. That way you can if then all keys. Sorry I must edit that a little.. I just realized the up, down, etc.. will not be in those. Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
Wchris Posted March 5, 2010 Author Share Posted March 5, 2010 I would use a function to pull the key ascii codes not the character. That way you can if then all keys. Hi Victor. What kind of function ? LE does only provide GetChar to return keycodes. Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
Rick Posted March 5, 2010 Share Posted March 5, 2010 Yeah I understand. I did the same thing that mimics the .NET way. The KeyPress() event is fired for printable keys and the KeyDown/KeyUp events are for all keys and pass to it the VK_ key. Which in this case would be the KEY_ keys. So what I did was call GetChar() and if the value was >= 32 I would fire the KeyPress event passing in the result from GetChar(). Then I created an array of all the KEY_ values (which is pretty easy because most are in sequence). Then looped through this array to see if KeyDown() on any. When it was I sent the value to the event. Quote Link to comment Share on other sites More sharing options...
Wchris Posted March 5, 2010 Author Share Posted March 5, 2010 Yeah I understand. I did the same thing that mimics the .NET way. The KeyPress() event is fired for printable keys and the KeyDown/KeyUp events are for all keys and pass to it the VK_ key. Which in this case would be the KEY_ keys. So what I did was call GetChar() and if the value was >= 32 I would fire the KeyPress event passing in the result from GetChar(). Then I created an array of all the KEY_ values (which is pretty easy because most are in sequence). Then looped through this array to see if KeyDown() on any. When it was I sent the value to the event. YES ! Fantastic ! So you encoutered the same problem as me ? GREAT ! (not that you had a problem, but that it was the same as me ) I was so desperate nobody would understand and have the same problem as me. OK this would work ... but between each frame you'll make a useless loop on all special keycodes that will eat FPS where LE could perfectly send you the right keycode with getchar i tryed to mail josh and explain this to him, but i think i failed. if there's no better solution i'll do like you ... but it's really frustrating If getchar only return characters because it's called "getCHAR" then we could need a "getKEYCODE" function that would return all pressed keycodes available ... well ... except if LE also needs to achieve a loop on all special keys to achieve this, of course. But normaly on windows you don't have to, windows sends the right keycode to the focused window. Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
Rick Posted March 5, 2010 Share Posted March 5, 2010 Look into kbhit(); It's a c++ non blocking method to tell when a key was hit. It should be cross platform also. You can use this to only loop through the array when a key is hit. http://www.cprogramming.com/fod/kbhit.html My bad, this isn't crossplatform. You would have to find the other platform equivalents and use a define when compiling it. I would think BMax would have something like what you are asking for since it's cross platform, but maybe Josh isn't exposing it. Quote Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted March 5, 2010 Share Posted March 5, 2010 Also, I would look into cin.get() If it is possible for your program, this will work. LE is in a console so you should be able to use that. Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
Rick Posted March 5, 2010 Share Posted March 5, 2010 I think cin.get() is blocking though. It'll halt there until a key is read in, which means your main loop won't run. Quote Link to comment Share on other sites More sharing options...
Masterxilo Posted March 5, 2010 Share Posted March 5, 2010 And it'll only register input to the console window of the application, which one will want to disable in the release version. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted March 5, 2010 Share Posted March 5, 2010 yeah. Thats a good point. Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
Wchris Posted March 6, 2010 Author Share Posted March 6, 2010 Hi Folks, i made some search. i wonder if this http://www.libsdl.org/ could be used with LE and if someone already tryed to use it ? It's cross platform and there is also joystick support Edit : i also found this http://en.wikipedia.org/wiki/OpenGL_Utility_Toolkit Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted March 6, 2010 Share Posted March 6, 2010 second link.... The library requires programmers to call glutMainLoop(), a function which never returns. This makes it hard for programmers to integrate GLUT into a program or library which wishes to have control of its own event loop. Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
panoramix Posted March 6, 2010 Share Posted March 6, 2010 I think GetAsyncKeyState is your answer // get async status on all keys SHORT myKeyboardState[256]; for (int x = 0; x < 256; x++) myKeyboardState[x] = GetAsyncKeyState(x); // now if you want to know about the up arrow key you do this if(myKeyboardState[VK_UP] & 0x8000) { // check for most significant bit // it's currently being pressed } Quote Desktop: Intel 2600K - Gigabyte Z68X-UD3H-B3 - 16GB G.Skill Sniper - EVGA 580 gtx - Raid0 OCZ Vertex 3 SSD - Win7 64bit. Link to comment Share on other sites More sharing options...
Rick Posted March 6, 2010 Share Posted March 6, 2010 He seems to be looking for a crossplatform solution :/ Quote Link to comment Share on other sites More sharing options...
panoramix Posted March 7, 2010 Share Posted March 7, 2010 well, that's even more confusing to me... this is the leadwerks forum right? I only get engine.dll and engine.exe... so, what exactly does he mean by crossplatform? Quote Desktop: Intel 2600K - Gigabyte Z68X-UD3H-B3 - 16GB G.Skill Sniper - EVGA 580 gtx - Raid0 OCZ Vertex 3 SSD - Win7 64bit. Link to comment Share on other sites More sharing options...
Rick Posted March 7, 2010 Share Posted March 7, 2010 I can only assume he's preparing for when LE becomes crossplatform? Quote Link to comment Share on other sites More sharing options...
Wchris Posted March 7, 2010 Author Share Posted March 7, 2010 I can only assume he's preparing for when LE becomes crossplatform? Yes. LE is written in blitzmax, a crossplatform language, and uses OpenGL a cross platform 3D api, so it would be a logical next step. But ok, even if josh said this could happen there is no guarantee yet. There are also some advantages of using a third party input library like joystick support, http://leadwerks.com/werkspace/index.php?/topic/505-joystick-support/page__p__4860__hl__joystick__fromsearch__1entry4860 i don't really need joystick yet in my game, but i want to provide the most open solution. Thank you for your kind answers it helped me alot to decide. Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.