Bonjour,

Depuis mon thread principal, je créé un thread secondaire où "une macro" s’exécute en boucle.

Thread Principal :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
std::stringstream  toucheecoutee("0x51");
std::stringstream  toucheenvoye("0x41");
std::thread t1(IfAPressSendB, toucheecoutee, toucheenvoye);
t1.join();

Thread Secondaire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
void IfAPressSendB(stringstream KeyListened, stringstream  KeySended)
{
    unsigned int ListenedHexVK;
    KeyListened << std::hex << "fffefffe";
    KeyListened >> ListenedHexVK;
 
    unsigned int SendedHexVK;
    KeySended << std::hex << "fffefffe";
    KeySended >> SendedHexVK;
 
    while(1)
    {
    if (GetAsyncKeyState(ListenedHexVK))
    {
        INPUT ip;
 
        ip.type = INPUT_KEYBOARD;
        ip.ki.wScan = 0;
        ip.ki.time = 0;
        ip.ki.dwExtraInfo = 0;
 
        ip.ki.wVk = SendedHexVK; // Hex code for 'A'
        ip.ki.dwFlags = 0; //Press the key down ?
        SendInput(1, &ip, sizeof(INPUT)); //Use function
 
        Sleep(50); //Sleep so it doesn't spam the key press
 
        ip.ki.dwFlags = KEYEVENTF_KEYUP; //Release the key
        SendInput(1, &ip, sizeof(INPUT)); //Use function
    }
    }
}
Au début, je convertis mes variables string (non utilisable en string puisque l'API attend un "int") en unsigned int, puis je les utilise en tant que tel. Voici les messages d'erreurs du compilateur :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
1>------ Début de la génération : Projet : ProjetMacroR6S, Configuration : Debug Win32 ------
1>ProjetMacroR6S.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\memory(2539): error C2664: 'std::tuple<void (__cdecl *)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void)),std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>,std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>::tuple(std::tuple<void (__cdecl *)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void)),std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>,std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>> &&)' : impossible de convertir l'argument 1 de '_Ty' en 'std::allocator_arg_t'
1>        with
1>        [
1>            _Ty=void (__cdecl &)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void))
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\memory(2538): note: Aucun constructeur n'a pu prendre le type de source, ou la résolution de la surcharge du constructeur était ambiguë
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\thread(46): note: voir la référence à l'instanciation de la fonction modèle 'std::unique_ptr<std::tuple<void (__cdecl *)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void)),std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>,std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>,std::default_delete<_Ty>> std::make_unique<std::tuple<void (__cdecl *)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void)),std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>,std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>,void(__cdecl &)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void)),std::stringstream&,std::stringstream&,0>(void (__cdecl &)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void)),std::stringstream &,std::stringstream &)' en cours de compilation
1>        with
1>        [
1>            _Ty=std::tuple<void (__cdecl *)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void)),std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>,std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>
1>        ]
1>c:\users\dridri\desktop\c++vsr6s\projet macro r6s\projetmacror6s\projetmacror6s.cpp(53): note: voir la référence à l'instanciation de la fonction modèle 'std::thread::thread<void(__cdecl &)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void)),std::stringstream&,std::stringstream&,void>(_Fn,std::stringstream &,std::stringstream &)' en cours de compilation
1>        with
1>        [
1>            _Fn=void (__cdecl &)(std::stringstream (__cdecl *)(void),std::stringstream (__cdecl *)(void))
1>        ]
1>Génération du projet "ProjetMacroR6S.vcxproj" terminée -- ÉCHEC.
========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========
J'ai l'impression que le problème vient du multithread ! PS : Je tiens à préciser que si je ne passe pas les VK comme attribut cela fonctionne ! Donc dans le main :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
std::thread t1(IfAPressSendB);
et le thread secondaire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
void IfAPressSendB(stringstream KeyListened, stringstream  KeySended)
{
    while(1)
    {
    if (GetAsyncKeyState(0x51))
    {
        INPUT ip;
 
        ip.type = INPUT_KEYBOARD;
        ip.ki.wScan = 0;
        ip.ki.time = 0;
        ip.ki.dwExtraInfo = 0;
 
        ip.ki.wVk = 0x41; // Hex code for 'A'
        ip.ki.dwFlags = 0; //Press the key down ?
        SendInput(1, &ip, sizeof(INPUT)); //Use function
 
        Sleep(50); //Sleep so it doesn't spam the key press
 
        ip.ki.dwFlags = KEYEVENTF_KEYUP; //Release the key
        SendInput(1, &ip, sizeof(INPUT)); //Use function
    }
    }
}
Là, ça fonctionne parfaitement. Mais mon but c'est de créer une fonction réutilisable alors... Quelqu'un a une idée ? Merci