Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    yodaliketaco's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    winsock.dll
    Posts
    645
    Reputation
    45
    Thanks
    514
    My Mood
    Tired

    What is wrong with my use of GetAsyncKeyState?

    I am getting compiler errors with my use of GetAsyncKeyState, but I am not sure why.

    These are my includes.

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <WinNT.h>
    #include <WinDef.h>
    #using <mscorlib.dll>
    using namespace System;
    using namespace std;
    The function is:

    Code:
    DWORD WINAPI tm1(LPVOID)
    {
    	CreateThread(NULL, NULL, tm2, NULL, NULL, NULL);
    	do
    	{
    		if(GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU) && GetAsyncKeyState(VK_DELETE))
    	{
    		system("start program.exe");
    		HANDLE console2 = GetStdHandle(STD_OUTPUT_HANDLE);
    		SetConsoleTextAttribute(console2, x++);
    		cout << "denied!";
    		x++;
    	}
    	}
    	while(TRUE);
    	return 0;
    }
    The function is declared before the main function.

  2. The Following User Says Thank You to yodaliketaco For This Useful Post:

    NOOB (06-23-2011)

  3. #2
    Lyoto Machida's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Far away with girls
    Posts
    3,734
    Reputation
    133
    Thanks
    1,621
    My Mood
    Aggressive
    I dont know but i think the error is here:
    Code:
    if(GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU) && GetAsyncKeyState(VK_DELETE))
    What if you try:
    Code:
    if(GetAsyncKeyState(VK_CONTROL)){
    if(GetAsyncKeyState(VK_MENU)){
    if(GetAsyncKeyState(VK_DELETE)){
    
    // FUNCTION
    
    }
    }
    }
    But idk really.

  4. The Following User Says Thank You to Lyoto Machida For This Useful Post:

    NOOB (06-23-2011)

  5. #3
    yodaliketaco's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    winsock.dll
    Posts
    645
    Reputation
    45
    Thanks
    514
    My Mood
    Tired
    Quote Originally Posted by Lyoto Machida View Post
    I dont know but i think the error is here:
    Code:
    if(GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU) && GetAsyncKeyState(VK_DELETE))
    What if you try:
    Code:
    if(GetAsyncKeyState(VK_CONTROL)){
    if(GetAsyncKeyState(VK_MENU)){
    if(GetAsyncKeyState(VK_DELETE)){
    
    // FUNCTION
    
    }
    }
    }
    But idk really.
    Even if I only use
    Code:
    if(GetAsyncKeyState(VK_CONTROL))
    {
    //FUNCTION
    }
    there are still compiler errors.

  6. The Following User Says Thank You to yodaliketaco For This Useful Post:

    NOOB (06-23-2011)

  7. #4
    Lyoto Machida's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Far away with girls
    Posts
    3,734
    Reputation
    133
    Thanks
    1,621
    My Mood
    Aggressive
    Quote Originally Posted by yodaliketaco View Post
    Even if I only use
    Code:
    if(GetAsyncKeyState(VK_CONTROL))
    {
    //FUNCTION
    }
    there are still compiler errors.
    Can you paste the errors?

  8. The Following User Says Thank You to Lyoto Machida For This Useful Post:

    NOOB (06-23-2011)

  9. #5
    yodaliketaco's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    winsock.dll
    Posts
    645
    Reputation
    45
    Thanks
    514
    My Mood
    Tired
    Errors:

    Code:
    error LNK2028: unresolved token (0A000353) "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "unsigned long __stdcall tm1(void *)" (?tm1@@$$FYGKPAX@Z)
    
    error LNK2019: unresolved external symbol "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "unsigned long __stdcall tm1(void *)" (?tm1@@$$FYGKPAX@Z)

  10. The Following User Says Thank You to yodaliketaco For This Useful Post:

    NOOB (06-23-2011)

  11. #6
    CAFlames's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Where ever my imagination takes me
    Posts
    3,006
    Reputation
    202
    Thanks
    2,944
    My Mood
    Twisted
    Quote Originally Posted by yodaliketaco View Post
    Errors:

    Code:
    error LNK2028: unresolved token (0A000353) "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "unsigned long __stdcall tm1(void *)" (?tm1@@$$FYGKPAX@Z)
    
    error LNK2019: unresolved external symbol "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "unsigned long __stdcall tm1(void *)" (?tm1@@$$FYGKPAX@Z)
    @yodaliketaco

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <WinNT.h>
    #include <WinDef.h>
    #using <mscorlib.dll>
    using namespace System;
    using namespace std;
    Code:
    DWORD WINAPI tm1(LPVOID)
    {
    	CreateThread(NULL, NULL, tm2, NULL, NULL, NULL);
    	do
    	{//bool them as true if control is held, menu is held, and delete is held.  
    bool Control = (GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0;
    bool Menu = (GetAsyncKeyState(VK_MENU) & 0x8000) != 0;
    bool Delete =(GetAsyncKeyState(VK_DELETE) & 0x8000) !=  0;
    		if(Control && Menu && Delete) //If all 3 are held at once
    	{
    		system("start program.exe");
    		HANDLE console2 = GetStdHandle(STD_OUTPUT_HANDLE);
    		SetConsoleTextAttribute(console2, x++);
    		cout << "denied!";
    		x++;
    	}
    	}
    	while(true);//I prefer this
    	return NULL;//Same /\
    }
    there ya go

    Current Works:
    ---Horror Game





    [IMG]https://i645.photobucke*****m/albums/uu180/drgnforce9/Siggys/signature3.jpg[/IMG]
    Special thanks to drgnforce9 for my sig picture

    Quote Originally Posted by m_t_h View Post

    CAflames is one epic coder.

    Rep and thanks him.. or you're perma banned.

  12. The Following 2 Users Say Thank You to CAFlames For This Useful Post:

    Lyoto Machida (06-12-2011),NOOB (06-23-2011)

  13. #7
    yodaliketaco's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    winsock.dll
    Posts
    645
    Reputation
    45
    Thanks
    514
    My Mood
    Tired
    Quote Originally Posted by CAFlames View Post


    @yodaliketaco

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <WinNT.h>
    #include <WinDef.h>
    #using <mscorlib.dll>
    using namespace System;
    using namespace std;
    Code:
    DWORD WINAPI tm1(LPVOID)
    {
    	CreateThread(NULL, NULL, tm2, NULL, NULL, NULL);
    	do
    	{//bool them as true if control is held, menu is held, and delete is held.  
    bool Control = (GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0;
    bool Menu = (GetAsyncKeyState(VK_MENU) & 0x8000) != 0;
    bool Delete =(GetAsyncKeyState(VK_DELETE) & 0x8000) !=  0;
    		if(Control && Menu && Delete) //If all 3 are held at once
    	{
    		system("start program.exe");
    		HANDLE console2 = GetStdHandle(STD_OUTPUT_HANDLE);
    		SetConsoleTextAttribute(console2, x++);
    		cout << "denied!";
    		x++;
    	}
    	}
    	while(true);//I prefer this
    	return NULL;//Same /\
    }
    there ya go

    @CAFlames
    That still gives the same compiler errors. I've never had this problem with GetAsyncKeyState before.

  14. The Following User Says Thank You to yodaliketaco For This Useful Post:

    NOOB (06-23-2011)

  15. #8
    CAFlames's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Where ever my imagination takes me
    Posts
    3,006
    Reputation
    202
    Thanks
    2,944
    My Mood
    Twisted
    Quote Originally Posted by yodaliketaco View Post

    @CAFlames
    That still gives the same compiler errors. I've never had this problem with GetAsyncKeyState before.
    Instead of GetAsyncKeyState, try just

    Code:
    bool Control = ((VK_CONTROL) & 0x8000) != 0;

    Current Works:
    ---Horror Game





    [IMG]https://i645.photobucke*****m/albums/uu180/drgnforce9/Siggys/signature3.jpg[/IMG]
    Special thanks to drgnforce9 for my sig picture

    Quote Originally Posted by m_t_h View Post

    CAflames is one epic coder.

    Rep and thanks him.. or you're perma banned.

  16. The Following 2 Users Say Thank You to CAFlames For This Useful Post:

    NOOB (06-23-2011),yodaliketaco (06-12-2011)

  17. #9
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Control.ModifierKeys wraps GetKeyState in managed C++, don't know about an alternative for GetAsyncKeyState
    Ah we-a blaze the fyah, make it bun dem!

  18. The Following User Says Thank You to Hell_Demon For This Useful Post:

    NOOB (06-23-2011)

  19. #10
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    I am facepalm. Linker errors because multiple of the same includes.

    Windows.h already includes the WinNT and WinDef or the includes in windows.h includes them.

    Just include windows.h
    Last edited by Auxilium; 06-12-2011 at 01:05 PM.

  20. The Following 3 Users Say Thank You to Auxilium For This Useful Post:

    Hell_Demon (06-12-2011),NOOB (06-23-2011),yodaliketaco (06-12-2011)

  21. #11
    yodaliketaco's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    winsock.dll
    Posts
    645
    Reputation
    45
    Thanks
    514
    My Mood
    Tired
    Quote Originally Posted by Virtual Void View Post
    I am facepalm. Linker errors because multiple of the same includes.

    Windows.h already includes the WinNT and WinDef or the includes in windows.h includes them.

    Just include windows.h
    Hmm... I see the problem with that, and I fixed it, but the compiler errors still exist.

    EDIT: CAFlames' solution gets rid of the compile errors, but doesn't respond to keypress during testing.
    Last edited by yodaliketaco; 06-12-2011 at 01:24 PM.

  22. The Following User Says Thank You to yodaliketaco For This Useful Post:

    NOOB (06-23-2011)

  23. #12
    mmbob's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    ja
    Posts
    653
    Reputation
    70
    Thanks
    1,157
    My Mood
    Bitchy
    Are you trying to mix C++ and C# or using managed C++?
    Code:
    #using <mscorlib.dll>
    using namespace System;
    looks managed to me.

    If you're trying to compile into a form-based application, that code won't work.
    Last edited by mmbob; 06-12-2011 at 01:23 PM.

  24. The Following User Says Thank You to mmbob For This Useful Post:

    NOOB (06-23-2011)

  25. #13
    yodaliketaco's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    winsock.dll
    Posts
    645
    Reputation
    45
    Thanks
    514
    My Mood
    Tired
    Quote Originally Posted by mmbob View Post
    Are you trying to mix C++ and C# or using managed C++?
    Code:
    #using <mscorlib.dll>
    using namespace System;
    looks managed to me.

    If you're trying to compile into a form-based application, that code won't work.
    It is a console application. I had mscorlib.dll because I was using DllImport
    Last edited by yodaliketaco; 06-12-2011 at 01:34 PM.

  26. The Following User Says Thank You to yodaliketaco For This Useful Post:

    NOOB (06-23-2011)

  27. #14
    proman98's Avatar
    Join Date
    Sep 2010
    Gender
    male
    Location
    Achel
    Posts
    1,024
    Reputation
    47
    Thanks
    81
    My Mood
    Fine
    the GetAsyncKeyState just dont like you

  28. The Following User Says Thank You to proman98 For This Useful Post:

    NOOB (06-23-2011)

  29. #15
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    Quote Originally Posted by proman98 View Post
    the GetAsyncKeyState just dont like you
    i just dont like you

  30. The Following User Says Thank You to Auxilium For This Useful Post:

    NOOB (06-23-2011)

Page 1 of 2 12 LastLast