Results 1 to 4 of 4

Thread: trying to send a key press

  1. #1
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,869
    Rep Power
    404

    trying to send a key press

    Since we use the Escape key to terminate our programs usually. I was trying to send a key press so simulate the user pressing ESCAPE
    to then start the termination of my application and to cleanup before doing so. Just as when then user presses the Escape key.

    I put this where I wanted to simulate the escape key press, but it doesn't work. Any ideas?
    hwnd is my windows handle.
    I also tried %WM_KEYDOWN, and it didn't work either.

    SendMessage(hwnd, %WM_KEYUP, %VK_ESCAPE, 0)

    Thanks.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  2. #2

    Re: trying to send a key press

    Hi kryton9,

    It can sometimes be done by putting code into window main loop


    IF getwindowkeystate( hWnd, %VK_RETURN) THEN
    ......
    ......
    ......
    ENDIF

    catventure.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,869
    Rep Power
    404

    Re: trying to send a key press

    THanks Catventure. I aready have such a loop for the escape key. I just wanted to mimic that from code elsewhere.
    I found a work around already, but it would be nice to know how to send the message. From reading at MSDN it seemed like that should work.
    But I saw other posts from coders, saying it doesn't work either. So I don't know, thought I would ask here.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10

    Re: trying to send a key press

    Ken,

    sending a message to a window is not so easy. SendMessage will put a message in the message queue of a specified window. To be able to get the message you need to handle the window message queue with getMessage but if this a TBGL window it is internally managed but TBGL module.

    I suppose you want to send a key like in old DOS time. If so, you can use SendKeys in UI module:

    [code=thinbasic]
    Sendkeys("{ESC}")
    [/code]

    Let me know.
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Send data to external companies
    By ErosOlmi in forum Real world situations and solutions using thinBasic
    Replies: 0
    Last Post: 09-10-2006, 17:06

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •