Change the ASCII of a given character

Just starting out? Need help? Post your questions and find answers here.
donSHAYA
User
User
Posts: 95
Joined: Wed Mar 25, 2009 9:57 am

Change the ASCII of a given character

Post by donSHAYA »

How do I change the ASCII code of a given character? Example: When I press on button A on my keyboard, B shall be pushed.

Thank You!
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

get the inkey... add 1 to whatever is pushed and output...

There is a malicious virus that does this... My sister managed to get a hold of it... terrible!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

this has nothing to do with ASCII and Charakter, but with Key and Scancode.
wich Key is associated to wich Char is determined by the Scancode, these are located in the CodePage.
Search these terms on MSDN.
oh... and have a nice day.
donSHAYA
User
User
Posts: 95
Joined: Wed Mar 25, 2009 9:57 am

...

Post by donSHAYA »

Can some of you give me an example code? Don't understand the inkey-thing. I tried to search on MSDN and I got BumpBar.SetKeyTranslation(), but can't find it in PB. An example code will be cool.
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Why not Search for Scancode on this forum ?
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

You can find great PB codes at PureBasic CodeArchiv: http://www.purearea.net/pb/CodeArchiv/English.html
This is modified from CodeArchiv 'KeyboardCatcher.pb':

Code: Select all

; http://www.purearea.net/pb/CodeArchiv/Input+Output/Keyboard/KeyboardCatcher.pb

Main = OpenWindow(0, 0, 0, 320, 200, "My Form", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

Repeat
  Event = WindowEvent()
  If Event = #WM_KEYUP
    key = EventwParam()
    Debug Str(key) + " = " + Chr(key)
    
    If key = 65 ; when released key 'A' simulate pressing key 'B'
      keybd_event_(#VK_B, 0, 0, 0) : keybd_event_(#VK_B, 0, #KEYEVENTF_KEYUP, 0)
    EndIf
  EndIf

  Delay(1) ; don't take all CPU power
Until Event = #PB_Event_CloseWindow
When you release key 'A' - it simulates pressing key 'B'.
Image
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Change the ASCII of a given character

Post by Blue »

Nice and so simple.

Any idea on how to catch scancodes in a similarly simple manner ? In theory you should be able to read scancodes using bits 16-23 of the same Windows message, but all i ever get is 0 :(
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Post Reply