News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Scancodes and ASCII characters

Started by brixton, June 16, 2005, 10:39:43 PM

Previous topic - Next topic

brixton

Hey all,

I was wondering how you could possible convert the hex value of the virtual-key code to the ASCII value of that key?

I don't know if there is a relation between virtual-key code, scan code or ASCII values.

If anyone can shed any light on the subject, I'd be more than happy!  :eek
If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..

Jimg

No, there's no relation or function you can apply other than table lookup.  If you look at the scan codes, you will see that they are generally just numbered sequentially across the keys on the keyboard.   a s d f are one after the other, etc.

Jeff

if i remember correctly, the virtual key code of the alphanumeric keys matches the ASCII (uppercase) alphanumeric keys.  so that should narrow down your work a little.

donkey

The API MapVirtualKey can convert a virtual key code to it's scan code.

The ToAscii function converts a virtual key code to ascii

The VkKeyScan function converts from ascii to virtual key code
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

brixton

Thankyou very much for the replies!

3 questions..

- The MapVirtualKey function, when using uMapType value 2 :

QuoteuCode is a virtual-key code and is translated into an unshifted character value in the low-order word of the return value.
Dead keys (diacritics) are indicated by setting the top bit of the return value. If there is no translation, the function returns 0.
What does the 'unshifted character value' represent?  An ascii character?  I don't understand.

- An unrelated question: If you have a bitmap on the clipboard, how can you save this to a file?

- Another question, can you use GetMessage or similar to get the messages of applications that don't belong to the current one?
If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..

doomsday

Quote- Another question, can you use GetMessage or similar to get the messages of applications that don't belong to the current one?

IIRC you can use SetWindowsHookEx to peek at messages from *all* running apps.  As you could imagine this could lead to slowing down the system if you're doing a lot of processing on each message, so I'd suggest using it very sparingly.

regards,
-Brent

brixton

Quote from: doomsday on June 18, 2005, 05:09:34 AMIIRC you can use SetWindowsHookEx to peek at messages from *all* running apps.  As you could imagine this could lead to slowing down the system if you're doing a lot of processing on each message, so I'd suggest using it very sparingly.
Thankyou for this, I'll mess around with it for a while!
If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..

TheGreatJason

Well, I'm progressing quite well through assembly language basics now, and I've got back to Icztutes! :U  After doing the Keyboard->ASCII one I decided to try to make my own one based on the key codes used in Windows instead.  I did manage to get it working but I did have some problems on the way...

One thing was I was trying to get the uninitialized variable called 'stringkey' to be local to WinProc but I didn't know how to define it.

Another thing was about Str<->Val conversions.  Is there anything in any of the libraries/include files that will do this job?  I had to write out the whole sequence of steps! :boohoo:  (But it works fine, so no big problem atm...)

Also, I suspect my program is not as efficient as it ought to be, so PLEASE have a look at it for me.  Or maybe it is just 100% useless, what do I know? :toothy

I also made a list of keycodes and the key combos that make them using my program for every button I have.  (My keyboard has 4 Windows keys... :dazzled:)  Ctrl+Shift+Break was a relatively hard one to get, a wonder I remembered about it as the emergency code exit in VB etc.  If there are any others like that I missed them so you'll have to tell me...

I have attached a .zip file containing the source code, executables and my keycode list so you can have a look for me.  Thanks in advance,

Jason

[attachment deleted by admin]

PBrennick

Jason,
I guess you meant 'keystring,' to make it local do the following:

    LOCAL keystring[3]:BYTE


I am attaching the source showing a successful build with this change. Also, you might want to consider using a dialog instead of a window. I am also attaching an example that shows how this is done, it is a general example but it is useful to show you what can be done.

Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

TheGreatJason

Umm, how come when you build it, the .exe is a whole KB smaller than mine??  I used 'ml /c /coff /Cp File.asm' and 'link /SUBSYSTEM:WINDOWS /LIBPATH:f:\masm32\lib File.obj' with all the latest release includes and library files in MASM32.

I know some of what can be done in Windows, being experienced in VB.  And all you need to do to see every useable object installed in your system (.dll and .ocx), by Microsoft or more likely not, is tick all the component boxes and they come up in a drag 'n' drop toolbar!!!  Also, you can add .exe objects into your forms such as the Microsoft Equation Editor.  I just tried it now, and it does work.  When you double click on it to edit an equation, it adds all of its menu items onto the window it is contained in and when it loses focus, they all disappear again.  (Actually it seems to depend HOW you click on it...)  You can even add the main part of the Windows Media Player v9.  If you sent it the right instructions it might actually work too...  If you go on the object library you can view all of its classes and enums and all the constants, properties, methods and events contained within.  Oops, LOL, it's easy to open a file in it.
WindowsMediaPlayer1.URL = "file:///F:/decider.mp3"
That music is strange...

The point is, how do you do this in assembly?

I have attached the entire project in a .zip, it would take about 5 mins or less to make the whole thing from scratch if I wanted to do it again.  I would have used the great Package and Deployment wizard to create an installer for it too.  Unfortunately it makes the project waaaaay over 256KB so I can't...

Sorry, but the program doesn't really do anything useful.  Unless you want to use it as a lightweight WMP.  Whatever you want...  I wouldn't be surprised if it just crashed as soon as you started it since I can't send you the installer.

N.B You need the wmp.dll file in your SYSTEM folder if this is going to have any chance of working.

I might try to make a smaller installer later by removing all the VB Runtime files from it...  (Why didn't I do that the first time?)  Oh, the .exe DEFINITELY won't work if you don't have that file.  But that's kind of obvious...

[attachment deleted by admin]

PBrennick

The reason for the smaller build is probably because I am using polink.exe instead of link.exe, it is a well known fact that Pelle's tools make smaller executables as he is automaticly merging some sections, etc.

Paul
The GeneSys Project is available from:
The Repository or My crappy website