Jump to content

Is there a Scan Code function?


Bytecroc
 Share

Recommended Posts

For Keyboard Input I can not found a way to get german umlaut like "ä,ö,ü,Ä,Ö,Ü,ß" also the Left- and right- Alt Key I am missing in the Keylist.

 

I miss in the API- Reference a function to get the scancode from a keypress.

Leadwerks 4.x Pro, examples please for C++,

english is not my native language.

Link to comment
Share on other sites

As far as I know, no, but you can fix this if you know the code of the key you want to use. Let's suppose that you are looking for key 1 (/exclamation mark, above Q), which would have the key code 49. Well, you can either use this value when you call the function

for example: window->KeyHit(49);

or open the external dependencies filter, go to Key.h and add it in the class

static const int KeyOne = 49;

...

window->KeyHit(Key::KeyOne);

 

//it would actually be advised to write your own Key class in case you want to share the code

 

I think that the issues with Alt key in windowed mode are related to the fact that it triggers the cascade menu.

Link to comment
Share on other sites

Thank you Undac and Athos for your answers and suggestions,

 

my WinAPI knowledge to replacing the windows wndproc with an own procedure is a bit to low

but the WinAPI did have some nice functions I tested.

 

This one works for the first.

It registers all Keys and also the mousebuttons smile.png

 

I think this are also not scancodes but I can make a list for each user to register his own keys.

Or receiving letters for input messages, like in a chat.

 

possibly replace the "comic.ttf" with "arial.ttf"

#include "App.h"
using namespace Leadwerks;
App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
App::~App() { delete world; delete window; }
bool App::Start()
{
window = Window::Create();
context = Context::Create(window);
Font* font = Font::Load("Fonts/Comic.ttf", 36, Font::Smooth);
context->SetFont(font);
font->Release();
return true;
}
bool App::Loop()
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
context->SetColor(0, 0, 0);
context->Clear();
context->SetColor(1, 1, 1);
//Display some centered text
std::string text;
BYTE keys[256];
//GetKeyState(0);
GetKeyboardState(keys);
for (int i=0; i < 255; i++)
{
if (keys[i] & 0x80)
{
text += String(i);
keys[i] = 0;
//break; //yes or no? The numbers for the right ALT Key and others are lower with break.
}
}
Font* font = context->GetFont();
int screenwidth = context->GetWidth();
int screenheight = context->GetHeight();
int x = (screenwidth - font->GetTextWidth(text)) / 2;
int y = (screenheight - font->GetHeight()) / 2;
context->SetBlendMode(Blend::Alpha);
context->DrawText(text, x, y);
context->SetBlendMode(Blend::Solid);
context->Sync();
return true;
}

Leadwerks 4.x Pro, examples please for C++,

english is not my native language.

Link to comment
Share on other sites

Extended to translate also in ScanCode

 

#include "App.h"
using namespace Leadwerks;
App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
App::~App() { delete world; delete window; }
unsigned long VKtoSC(unsigned long virtual_key)
{
return (static_cast<unsigned long>(::MapVirtualKeyEx(virtual_key, 4, ::GetKeyboardLayout(::GetCurrentThreadId()))));
}
bool App::Start()
{
window = Window::Create();
context = Context::Create(window);
Font* font = Font::Load("Fonts/Comic.ttf", 36, Font::Smooth);
context->SetFont(font);
font->Release();
return true;
}
bool App::Loop()
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
context->SetColor(0, 0, 0);
context->Clear();
context->SetColor(1, 1, 1);
//Display some centered text
std::string text;
std::string text2;
int sc;
BYTE keys[256];
//GetKeyState(0);
GetKeyboardState(keys);
for (int i=0; i < 255; i++)
{
 if (keys[i] & 0x80)
 {
  text = "VirtualKeyCode: " + String(i);
  sc = VKtoSC(i);
  text2 = "ScanCode: " + String(sc);
  //keys[i] = 0;
  //break;
 }
}
Font* font = context->GetFont();
int screenwidth = context->GetWidth();
int screenheight = context->GetHeight();
int x = (screenwidth - font->GetTextWidth(text)) / 2;
int y = (screenheight - font->GetHeight()) / 2;
context->SetBlendMode(Blend::Alpha);
context->DrawText(text, x, y);
context->DrawText(text2, x, y+50);
context->SetBlendMode(Blend::Solid);
context->Sync();
return true;
}

  • Upvote 1

Leadwerks 4.x Pro, examples please for C++,

english is not my native language.

Link to comment
Share on other sites

It's because english is not my natural language and I can not explain like I would do in my natural language what the problem 100% is.

Sometimes there are hidden functions or functions I have not detected inside Leadwerks, and before I use WinAPI things I thought I ask in forum.

For single key query there is GetKeyState() or GetAsyncKeyState() a better choice.

Leadwerks 4.x Pro, examples please for C++,

english is not my native language.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...